[SOLVED] Define chainToQuery from getchainID

Hi there,

I was trying to get all erc balance using

const balances = await Moralis.Web3.getAllERC20( { chainId: chainToQuery })

I have difficulties on defining chainToQuery as this script showing number/hex instead of string (looking for “bsc” or “bsc testnet”)

const chainToQuery = await web3.eth.getChainId();

Looking forward your advice.

an example:

    res = await Moralis.Web3API.account.getTokenBalances({
		chain: 'bsc',
		address: '0x0bfB6a9B57c15f0D97BAC8B7B491234927a6ECA2'
	})

    res = await Moralis.Web3API.account.getTokenBalances({
		chain: 'bsc testnet',
		address: '0x0bfB6a9B57c15f0D97BAC8B7B491234927a6ECA2'
	})

Some SDK functions have a new version in Moralis.Web3API now.
You should update Moralis SDK to latest version in case that you are using an older version.

2 Likes

cool, it finally works. thank you!

1 Like