This is snippet of my code.
const getBalance = (userAddress: String) => {
const provider = new Web3((window as any).web3.currentProvider);
const bnbContract = new provider.eth.Contract(bnbTokenAbi, tokenAddress);
bnbContract.methods.balanceOf(userAddress).call().then((res: any) => {
setBalance(res);
}).catch((err: any) => {
console.log(err);
});
}
But only the catch function works, what's the reason?
balanceof is used for any token but bnb or eth and all the main token of the chains correct function is balance address.balance
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.