如何获得USDT余额BEP-20? web3.eth.getBalance
Posted
技术标签:
【中文标题】如何获得USDT余额BEP-20? web3.eth.getBalance【英文标题】:How get USDT balance BEP-20? web3.eth.getBalance 【发布时间】:2022-01-15 22:31:27 【问题描述】:美好的一天!你能告诉我如何获得USDT地址的余额吗?我找到了获取BNB余额的方法(https://docs.binance.org/smart-chain/developer/BEP20.html),但是没有USDT的例子
【问题讨论】:
【参考方案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);
【讨论】:
以上是关于如何获得USDT余额BEP-20? web3.eth.getBalance的主要内容,如果未能解决你的问题,请参考以下文章