Fetch token balance react

Hello Everyone, how to fetch the balance of tokens available at a particular address?. I tried to use getAllERC20() function and getTokenBalance() function but It’s not working so is there any other way to solve this issue?
Thank you :slight_smile:

Make sure to pass in the right chainId and wallet address as the parameters. Do you get any errors? You can post your code.

You can also use useERC20Balances or useNFTBalances if you’re using React with the react-moralis library.

 const TokenBalance = async() => {
    const balances = await Moralis.web3.getAllERC20();
Wrote this code. 
And getting an error:-  

Uncaught (in promise) TypeError: moralis__WEBPACK_IMPORTED_MODULE_0___default(...).web3.getAllERC20 is not a function at TokenBalance (main.fe007bcbccf3d9ae97df.hot-update.js:33:80) at HTMLUnknownElement.callCallback (bundle.js:132469:18) at Object.invokeGuardedCallbackDev (bundle.js:132518:20) at invokeGuardedCallback (bundle.js:132580:35) at invokeGuardedCallbackAndCatchFirstError (bundle.js:132595:29) at executeDispatch (bundle.js:137424:7) at processDispatchQueueItemsInOrder (bundle.js:137456:11) at processDispatchQueue (bundle.js:137469:9) at dispatchEventsForPlugins (bundle.js:137480:7) at bundle.js:137672:16

Should be await Moralis.Web3API.account.getTokenBalances();. You should try take a look at the link @glad shared above.

Okay, Thank you @glad and @qudusayo :slight_smile:.

1 Like