[SOLVED] getTokenBalances() for MATIC return an empty array

So my Dapp right now operates on Polygon Mumbai Network
and i try to get user balance by running this function

const fetchTokenBalances = async () => {
    const options = {
      chain: "mumbai",
      address: walletAddress
    };
    const balances = await Web3Api.account.getTokenBalances(options);
  };

i already connected to metamask
Screenshot_19

but whenever i try to run the function its always return me an empty array.

anyone can help me? thanks!

you can try to use console log to see what are the values sent to web3api, you can also look in network tab, you can also try directly in web3api interface: https://admin.moralis.io/web3apis

i try it directly in https://admin.moralis.io/web3apis
but its also return me an empty array

erc20 is not same thing as native balance

which one do i use for get matic balance? getNativeBalances() or getTokenBalances() ? sorry im beginner

you have to use this one for native balance

this is the return message
Screenshot_21

i only have 0.2 Matic, is there any way i can convert it?

now you have to learn how to convert that number from WEI

do you have any docs for doing that?

yes, there is documentation for that

https://v1docs.moralis.io/moralis-dapp/tools/moralis-units

1 Like

the problem solved. thanks!

1 Like