Good day! Can you please tell me how you can get the balance of the USDT address? I found a way to get BNB balance (https://docs.binance.org/smart-chain/developer/BEP20.html), but there is no example for USDT
Asked
Active
Viewed 6,540 times
1 Answers
3
Token balance of an address is not a property of the address. It is stored in each of the token's contract. So you need to call the balanceOf()
function of the token contract, passing it the holder address as a parameter.
For example the BUSD token:
const busdAddress = "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56";
const holderAddress = "0x8894e0a0c962cb723c1976a4421c95949be2d4e3";
// just the `balanceOf()` is sufficient in this case
const abiJson = [
{"constant":true,"inputs":[{"name":"who","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},
];
const contract = new web3.eth.Contract(abiJson, busdAddress);
const balance = await contract.methods.balanceOf(holderAddress).call();
// note that this number includes the decimal places (in case of BUSD, that's 18 decimal places)
console.log(balance);

Petr Hejda
- 40,554
- 8
- 72
- 100
-
How can we get the balance of these proxy tokens? Ex -https://bscscan.com/token/0xbf5140a22578168fd562dccf235e5d43a02ce9b1#readProxyContract – Ajoy Karmakar Jan 19 '22 at 10:04
-
@AjoyKarmakar You can treat the proxy address as any other address. If the contract implementation is hidden under the proxy address, you can pass the proxy address to the `Contract` JS class. If you're interested in token balance of the proxy address, you set it as the `holderAddress` in the above snippet... As for the shared Uniswap proxy contract: If you want to know how much UNI tokens are owned by this (Uniswap) proxy contract, pass the proxy address to both places. – Petr Hejda Jan 19 '22 at 10:09
-
Tried 'you can pass the proxy address to the Contract JS class' but it's showing me a balance of 0. – Ajoy Karmakar Jan 19 '22 at 11:34
-
const otherContract = await new web3.eth.Contract( abi, '0xba5fe23f8a3a24bed3236f05f2fcf35fd0bf0b5c' ); const otherBalance = await otherContract.methods .balanceOf('0xa859D1f24F27B550bf4ba3B54D15d88D51Df5018') .call(); console.log('otherBalance', otherBalance); – Ajoy Karmakar Jan 19 '22 at 11:34
-
@AjoyKarmakar The result is correct. The USDC contract address doesn't own any USDC tokens. You can verify this by passing the `0xba5f...` address to the `balanceOf()` function on the [contract detail](https://bscscan.com/address/0xba5fe23f8a3a24bed3236f05f2fcf35fd0bf0b5c#readContract) page on BSCScan. – Petr Hejda Jan 19 '22 at 11:53
-
Basically you are saying right but how do I get the UNI balance of my account? – Ajoy Karmakar Jan 19 '22 at 12:12
-
@AjoyKarmakar To get the UNI balance of your account, you pass the UNI proxy address to the `Contract` JS object, and your address to the `balanceOf()` function. – Petr Hejda Jan 19 '22 at 12:25