I have this code to show the erc20 token balance of an account
var tokenAddress = '0xb97E9bBB6fd49865709d3F1576e8506ad640a13B';
var walletAddress = '0x62f28320f688A7A4e0021c55d7ffD1acd770A133';
function getERC20TokenBalance() {
let minABI = [
// balanceOf
{
"constant":true,
"inputs":[{"name":"_owner","type":"address"}],
"name":"balanceOf",
"outputs":[{"name":"balance","type":"uint256"}],
"type":"function"
},
// decimals
{
"constant":true,
"inputs":[],
"name":"decimals",
"outputs":[{"name":"","type":"uint8"}],
"type":"function"
}
];
let contract2 = web3.eth.contract(minABI).at(tokenAddress);
web3.eth.getAccounts(function (error, walletAddress) {
contract2.balanceOf(walletAddress, function(err, result) {
if(err) {
console.log(err, 'err');
} else {
console.log(result);
document.getElementById('agiAvailable').innerHTML = result + ' AGI';
}
});
});
}
getERC20TokenBalance();
function onAddressChange(e) {
if(tokenAddress != "" && walletAddress != "") {
getERC20TokenBalance(tokenAddress, walletAddress, (balance) => {
console.log(balance.toString());
});
}
}
But that output is 0, which is not the correct balance