> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# useTokenBalances

<Card title="Recommended: JavaScript SDK with React Hooks" icon="react" color="#4779FE">
  For new React apps, we recommend the JavaScript SDK with React Hooks (`@dynamic-labs-sdk/react-hooks`) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the [React quickstart (JavaScript SDK)](/javascript/reference/react-quickstart) to get started.
</Card>

### Summary

Used to fetch the token balances of an account on a specified network. The default behavior is to return the token balances of the primary account on the current network, but optionally the account, network, includeFiat and includeNativeBalance can be specified.

Chain support includes 66 EVM networks, Solana Mainnet and Devnet, Eclipse Mainnet and Bitcoin Ruins. You can checkout the full list [here](/react/reference/token-balances#supported-chains)

<Note>
  This will return all tokens with at least 10,000 USD in liquidity unless using `filterSpamTokens: false` in the hook parameters. This applies to total token liquidity.
</Note>

### Usage

```jsx theme={"system"}
import { useTokenBalances } from "@dynamic-labs/sdk-react-core";

const { tokenBalances, isLoading, isError, error } = useTokenBalances();
```

```json theme={"system"}
// tokenBalances
[
  {
    "networkId": 1,
    "address": "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0",
    "name": "Polygon",
    "symbol": "MATIC",
    "decimals": 18,
    "logoURI": "https://assets.coingecko.com/coins/images/4713/thumb/polygon.png?1698233745",
    "balance": 0.7851804304793578,
    "rawBalance": 785180430479357800,
    "rawBalanceString": "785180430479357800",
    "price": 0.703229,
    "marketValue": 0.5521616489455683
  },
  {
    "networkId": 1,
    "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    "name": "USDC",
    "symbol": "USDC",
    "decimals": 6,
    "logoURI": "https://assets.coingecko.com/coins/images/6319/thumb/usdc.png?1696506694",
    "balance": 50,
    "rawBalance": 50000000,
    "rawBalanceString": "50000000",
    "price": 1,
    "marketValue": 50
  }
]
```

#### With arguments

| Parameter            | Type      | Description                                           |
| :------------------- | :-------- | :---------------------------------------------------- |
| networkId            | Number    | The network ID                                        |
| chainName            | ChainEnum | The chain used                                        |
| tokenAddresses       | String\[] | The token addresses                                   |
| includeFiat          | Boolean   | Should include Fiat prices                            |
| includeNativeBalance | Boolean   | Should include native balance                         |
| forceRefresh         | Boolean   | Refreshes the cached balances                         |
| filterSpamTokens     | Boolean   | Defaults to true to filter spam tokens out            |
| whitelistedContracts | String\[] | Return these contracts, even when originally filtered |

Optionally, you can pass an object with the account address and network id specified. Additionally, you can pass an array of token addresses to filter the results.

```jsx theme={"system"}
import { useTokenBalances } from "@dynamic-labs/sdk-react-core";

const { tokenBalances, isLoading, isError, error } = useTokenBalances({
  networkId: 1,
  accountAddress: "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0",
  includeFiat: true,
  includeNativeBalance: true,
});

return (
  <ul>
    {tokenBalances?.map((tokenBalance) => (
      <li key={tokenBalance.address}>
        {tokenBalance.name} {tokenBalance.balance} {tokenBalance.symbol} ($
        {tokenBalance.price}) | ${tokenBalance.marketValue}
      </li>
    ))}
  </ul>
);
```

Refresh token balances after a transaction

```jsx theme={"system"}
import { useTokenBalances } from "@dynamic-labs/sdk-react-core";
import { ChainEnum } from "@dynamic-labs/sdk-api-core";

const { fetchAccountBalances, tokenBalances, isLoading, isError, error } = useTokenBalances({
  chainName: ChainEnum.Evm,
  accountAddress: address,
  includeFiat: true,
  includeNativeBalance: true,
});

// send transaction
const txHash = await sendTransaction({...});
// wait for transaction receipt
await publicClient.waitForTransactionReceipt(txHash);
// refresh token balances once the transaction receipt has resolved
fetchAccountBalances(true);
```

```jsx theme={"system"}
// with token addresses filter
import { useTokenBalances } from "@dynamic-labs/sdk-react-core";

const { tokenBalances, isLoading, isError, error } = useTokenBalances({
  networkId: 1,
  accountAddress: "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0",
  tokenAddresses: ["0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0"],
});
```

Solana support with Fiat prices (with SDK version 2.2.9)

```jsx theme={"system"}
import { useTokenBalances } from "@dynamic-labs/sdk-react-core";
import { ChainEnum } from "@dynamic-labs/sdk-api";

const { tokenBalances, isLoading, isError, error } = useTokenBalances({
  chainName: ChainEnum.Sol,
  accountAddress: address,
  includeFiat: true,
  includeNativeBalance: true,
});
```
