Rise In Logo



Build on Chiliz

Implementing Frontend III - Getting Token Balances

In the videos we are showing the conventional way yet in case you face problems with EvmApi, it is due to incompleteness of CHZ integration in Moralis.

You can check this link for balances.

For fetching native_balance and token_balances you can use the following code instead:

const token_balances = await fetch(
 `https://deep-index.moralis.io/api/v2.2/0x6648560A1a5800BE0843D987297bDe5D4b240Ab1/erc20?` +
  new URLSearchParams({
   chain: current_chain,
  }),
 {
  method: 'get',
  headers: {
   accept: 'application/json',
   'X-API-Key': `${apiKey}`,
  },
 },
);

const tokens = await token_balances.json();
setTokenBalances(tokens);

const native_balance = await fetch(
 `https://deep-index.moralis.io/api/v2.2/0x057Ec652A4F150f7FF94f089A38008f49a0DF88e/balance?` +
  new URLSearchParams({
   chain: current_chain,
  }),
 {
  method: 'get',
  headers: {
   accept: 'application/json',
   'X-API-Key': `${apiKey}`,
  },
 },
);
const native = await native_balance.json();
setNativeBalance(native);

Comments

Anonymous

0/500

You need to enroll in the course to be able to comment!

Stay in the know

Never miss updates on new programs and opportunities.

Rise In Logo

Rise together in web3!