How to get the balance of a wallet

What is the CHZ balance of a wallet?

The balance of a wallet refers to the total amount of a specific cryptocurrency that the wallet holds. Depending on your project, you might be need to display the balance of a single cryptocurrency, or the balances of all cryptocurrencies that a wallet holds.

Likewise, wallet assets refer to all forms of cryptocurrencies, tokens, and digital assets that are stored and managed within a cryptocurrency wallet.

How to do it with Moralis

Moralis has a Wallet APIarrow-up-right that you can make use of, and they even provide a code sample for the wallet balance use-case:

To adapt their code sample, we need to replace the reference to Ethereum with their ID for Chiliz Chain, 0x15b38:

import Moralis from "moralis";

const runApp = async() => {
  await Moralis.start({
    apiKey: "YOUR_API_KEY",
    // ...and any other configuration
  });

  const address = "0xYourWalletAddress";

  const chain = "0x15b38", // This is for Chiliz Chain Mainnet.
                           // For Spicy Testnet, use "0x15b32".

  const response = await Moralis.EvmApi.balance.getNativeBalance({
    address,
    chain,
  });

  console.log(response.toJSON());
};

runApp();

How to do it with Tatum

Tatum has a comprehensive Data APIarrow-up-right that you can make use of, and they even provide a code sample for the asset-retrieval use-case:

To adapt their code sample, we need to replace the reference to Ethereum with Chiliz Chain:

How to do it with thirdweb

thirdweb has several short code samples on their docs site, which we can use as an inspiration.

Here is their code, adapted to Chilizarrow-up-right:

How to do it using Nodit

Nodit provides the following code sample in their docarrow-up-right:

Last updated

Was this helpful?