BEP-20如何获取USDT余额? web3.eth.getBalance

How get USDT balance BEP-20? web3.eth.getBalance

美好的一天!能告诉我如何获取USDT地址的余额吗?我找到了获取 BNB 余额的方法 (https://docs.binance.org/smart-chain/developer/BEP20.html),但是没有 USDT 的示例

地址的代币余额是不是地址的属性。它存储在每个代币的合约中。所以你需要调用代币合约的balanceOf()函数,将持有者地址作为参数传递给它。

例如 BUSD 令牌:

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);