0

再会!你能告诉我如何获得USDT地址的余额吗?我找到了获得 BNB 余额的方法(https://docs.binance.org/smart-chain/developer/BEP20.html),但没有 USDT 的例子

4

1 回答 1

1

地址的代币余额不是地址的属性。它存储在每个代币的合约中。所以你需要调用代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);
于 2021-12-11T22:32:08.437 回答