A Pen by Rob Stupay on CodePen.
Created
April 21, 2020 02:04
-
-
Save ryestew/e5279902c842f483eae7221f6e2fbe9c to your computer and use it in GitHub Desktop.
MWajzre
This file contains 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
(async () => { | |
const account1 = '0xaaFBc70D3a20Ca41423ef8Df3C87c5A3Dd8327A5' | |
const contractAddress = '0x0C0A99BFA42050A31B4F474eAd0cd9132EEAFA19' | |
console.log('start') | |
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'browser/artifacts/CustomERC20.json')) | |
const accounts = await web3.eth.getAccounts() | |
// MetaMask injects a Web3 Provider as "web3.currentProvider", so | |
// we can wrap it up in the ethers.js Web3Provider, which wraps a | |
// Web3 Provider and exposes the ethers.js Provider API. | |
const provider = new ethers.providers.Web3Provider(web3.currentProvider); | |
// There is only ever up to one account in MetaMask exposed | |
const signer = provider.getSigner(); | |
provider.getBalance(address).then((balance) => { | |
// balance is a BigNumber (in wei); format is as a sting (in ether) | |
let etherString = ethers.utils.formatEther(balance); | |
console.log("Balance: " + etherString); | |
}); | |
let contract = new web3.eth.Contract(metadata.abi, contractAddress) | |
contract.methods.transfer(account1, 10000).send({ from: accounts[0] }).on('receipt', async (receipt) => { | |
console.log(receipt) | |
const result = await contract.methods.balanceOf(account1).call({from: account1}) | |
console.log('balance_', result) | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment