Skip to content

Instantly share code, notes, and snippets.

@hayesgm
Created June 3, 2020 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayesgm/7c7db3b8e219bd1eb5ccc93259ad2412 to your computer and use it in GitHub Desktop.
Save hayesgm/7c7db3b8e219bd1eb5ccc93259ad2412 to your computer and use it in GitHub Desktop.
let Eth = {
read: (network, contract, fn, args, ethers=require('ethers')) =>
Object.entries(
new ethers.Contract(
contract,
[fn],
new ethers.providers.InfuraProvider(network)
).functions
)[0][1](...args),
write: (network, contract, fn, args, pk=process.env('ethereum'), ethers=require('ethers')) =>
Object.entries(
new ethers.Contract(
contract,
[fn],
new ethers.Wallet(
pk,
new ethers.providers.InfuraProvider(network)
)
).functions)[0][1](...args)
};
await Eth.read('ropsten', '0x1Fe16De955718CFAb7A44605458AB023838C2793', 'balanceOf(address) view returns (uint)', ["0x513c1ff435eccedd0fda5edd2ad5e5461f0e8726"]);
await Eth.write('ropsten', '0x1Fe16De955718CFAb7A44605458AB023838C2793', 'transfer(address,uint)', ["0x513c1ff435eccedd0fda5edd2ad5e5461f0e8726", 10]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment