Answer the question
In order to leave comments, you need to log in
How to view the balance of the most famous ERC20 tokens of a user?
const web3 = new Web3(Web3.givenProvider);
const tokenAddresses = [
'0x',
'0x',
];
const myAddress = "0x";
for (let tokenAddress of tokenAddresses) {
const contract = new web3.eth.Contract(erc20AbiJson, tokenAddress);
const tokenBalance = await contract.methods.balanceOf(myAddress).call();
console.log(tokenBalance);
}
Answer the question
In order to leave comments, you need to log in
Addresses of token contracts can be viewed here https://etherscan.io/tokens - there are about 1000 of the most popular
const erc20Contracts = [
{ address: '0xdac17f958d2ee523a2206206994597c13d831ec7', name:'Tether USD' , ticker:'USDT'}
];
for (let token of erc20Contracts) {
const contract = new web3.eth.Contract(erc20AbiJson, token.address);
const tokenBalance = await contract.methods.balanceOf(myAddress).call();
console.log(token.name+': '+ web3.utils.fromWei(tokenBalance));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question