# 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 API](https://moralis.com/api/wallet/) that you can make use of, and they even provide a code sample for the wallet balance use-case:&#x20;

* [How to get the native balance of an address](https://docs.moralis.io/web3-data-api/evm/wallet-api/how-to-get-the-balance-of-a-wallet)

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

```typescript
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 API](https://tatum.io/blockchain-api) that you can make use of, and they even provide a code sample for the asset-retrieval use-case:

* [Get all assets the wallet holds](https://docs.tatum.io/docs/get-all-assets-the-wallet-holds)

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

```typescript
import {TatumSDK, Network, Chiliz, ResponseDto, AddressBalance} from '@@tatumio/tatum'

const tatum = await TatumSDK.init<Chiliz>({network: Network.CHILIZ})

const balance: ResponseDto<AddressBalance[]> = await tatum.address.getBalance({
  addresses: ['0xYourWalletAddress'], // replace with your address
})

console.log(balance.data)
```

## How to do it with thirdweb

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

* [Get wallet balance](https://portal.thirdweb.com/connect/in-app-wallet/how-to/interact-with-wallets#get-wallet-balance)

Here is their code, [adapted to Chiliz](https://thirdweb.com/chiliz-chain):&#x20;

```typescript
const sdk = new ThirdwebSDK("https://88888.rpc.thirdweb.com");
const walletAddress = "0xYourWalletAddress";

async function getWalletBalance() {
  try {
    const balance = await sdk.getBalance(walletAddress);
    console.log(`Balance of wallet ${walletAddress}: ${balance.displayValue} ${balance.symbol}`);
  } catch (error) {
    console.error("Error fetching wallet balance:", error);
  }
}

getWalletBalance();
```

## How to do it using Nodit

Nodit provides the following code sample [in their doc](https://developer.nodit.io/reference/chiliz-getnativebalancebyaccount):

```typescript
const url = 'https://web3.nodit.io/v1/chiliz/mainnet/native/getNativeBalanceByAccount';
const options = {
  method: 'POST',
  headers: {
    accept: 'application/json',
    'content-type': 'application/json',
    'X-API-KEY': 'nodit-demo'
  },
  body: JSON.stringify({accountAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'})
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```
