I just wanted to share a snippet of code that I've been working on:
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);
});
}
Interestingly, only the catch function seems to be working. Can anyone help me figure out why?