[SOLVED] Received empty array when use getTokenBalances

Hi, Im trying to get the token balance of one address using the method getTokenBalances but I receive an empty array.

const getTokenBalance = async () => {
    const response = await Moralis.Web3API.account.getTokenBalances({
      chain: 'eth',
      address: '0x3d6c0e79a1239df0039ec16Cc80f7A343b6C530e',
    });

    console.log(response);
};

response

[]

So, I trying a lot of thing. When I change the function to getNativeBalance, I receive all Ok.

const getTokenBalance = async () => {
    const response = await Moralis.Web3API.account.getNativeBalance({
      chain: 'eth',
      address: '0x3d6c0e79a1239df0039ec16Cc80f7A343b6C530e',
    });

    console.log(response);
};

response:

{balance: '19340262679426503'}

I think the problem its the method getTokenBalances

So my question its how I can get the token balancer for one address.

are there erc20 tokens for that address?

Yes, just in case I changed the address and got exactly the same empty array

this returns 3 results

response = await Moralis.Web3API.account.getTokenBalances({
      chain: 'eth',
      address: '0xAfc53dB8506736e8264b4629E971a152Ec3FF7D4',
    });
1 Like

@cryptokid I thinking about what you said, I came to the solution. Effectively the address doesn’t have an erc20 token but native tokens.

Thank you very much, this question is closed

1 Like