Created
June 3, 2020 23:18
-
-
Save hayesgm/7c7db3b8e219bd1eb5ccc93259ad2412 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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