New SDK and token balance

It used to be possible to get balance of a specific token using the following SDK function:

options = { chain: "mumbai", tokenAddress: myTokenAddress};
await Moralis.Web3.getERC20(options)

The function still works, However I don’t see this function in the documentation page

The closest thing I see on there is the following:

await Moralis.Web3API.account.getTokenBalances(options);

But this function gets balances for ALL tokens. If i include the tokenAddress, value in options, it ignores that value.

Given that the SDK was updated a few days ago, does this mean that the Moralis.Web3.getERC20() function has been deprecated? Or will it continue to get supported?


Hey @bobbington

Moralis.Web3 is an old syntax and will be deleted soon. We have expanded the functionality of the Moralis SDK and now you need to use Moralis.Web3API it has more functions.

Take a look at:

If you want to get balance for specific token you can use .find:

options = { chain: "mumbai" };
const balances = await Moralis.Web3API.account.getTokenBalances(options);
const tokenAddress =  "0x....9"; // You can specify for example: tokenAddress, name or symbol
const tokenBalance= balance.find((token) => token.token_address === tokenAddress);

Happy BUIDLing :man_mechanic:


Cheers! Thank you so much for the clarification, and for providing a workaround that is compatible with the new SDK :slight_smile:

Do you know if something like Moralis.Web3.getERC20(options) will make its way back into the new SDK? It was such a simple and clean way of getting the desired information.

1 Like

You are welcome!

Yes, it’s on the roadmap. It will be added :man_mechanic: