Skip to main content

Documentation Index

Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt

Use this file to discover all available pages before exploring further.

For most apps, prefer getMultichainTokenBalances — it batches token balances across chains, networks, and addresses in a single call. Reach for getTokenBalances only when you have one wallet on one chain (still fine across multiple networks of that chain) and want a simpler call shape.
You can get the token balances for a wallet account by calling the getTokenBalances function. This returns native and token balances for a single chain (one or more networks of that chain), unlike getMultichainTokenBalances which queries across multiple chains in one call. If you only need the native token balance, use getNativeBalance instead.

Usage

import { getTokenBalances } from '@dynamic-labs-sdk/client';

const balances = await getTokenBalances({ walletAccount });

With options

import { getTokenBalances } from '@dynamic-labs-sdk/client';

const balances = await getTokenBalances({
  walletAccount,
  networkId: 137,
  includePrices: true,
  includeNative: true,
  filterSpamTokens: true,
  forceRefresh: true,
  whitelistedContracts: ['0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174'],
});

Parameters

ParameterTypeRequiredDescription
walletAccountWalletAccountYesThe wallet account to get the balances for
networkIdnumberNoThe network ID to query. Defaults to the active network
includePricesbooleanNoInclude token prices in the response
includeNativebooleanNoInclude the native token balance
filterSpamTokensbooleanNoFilter out spam tokens (default: true)
forceRefreshbooleanNoForce a refresh instead of using cached values
whitelistedContractsstring[]NoOnly return balances for these contract addresses

React

Fetch balances in a useEffect and refresh when the wallet account changes:
import { getTokenBalances } from '@dynamic-labs-sdk/client';
import { useEffect, useState } from 'react';

function TokenBalances({ walletAccount }) {
  const [balances, setBalances] = useState([]);

  useEffect(() => {
    if (!walletAccount) return;
    getTokenBalances({ walletAccount, includePrices: true }).then(setBalances);
  }, [walletAccount]);

  return (
    <ul>
      {balances.map((token) => (
        <li key={token.address ?? 'native'}>
          {token.symbol}: {token.balance}
        </li>
      ))}
    </ul>
  );
}

Response

Returns a Promise<TokenBalance[]> — an array of token balance objects.