Skip to main content

useTokenBalance

The useTokenBalance hook fetches token balances for a connected wallet with optional automatic refresh intervals.

Import

Signature

Parameters

UseTokenBalanceParams

Returns

UseTokenBalanceReturn

Features

  • Automatic refresh - Set refetchInterval to keep balances up to date
  • Smart formatting - Balances are formatted with appropriate precision
  • Native token support - Use 'native' for chain native tokens
  • Stale-while-revalidate - Previous balance shown during refresh
  • Controlled fetching - Use enabled to pause/resume

Basic Usage

Auto-Refresh Example

Keep balances updated automatically:

Native Token Balance

Fetch the native token balance (ETH, MATIC, etc.):
You can also use the zero address (0x0000000000000000000000000000000000000000) instead of 'native'.

Multiple Token Balances

Display balances for multiple tokens:

Conditional Fetching

Control when balances are fetched:

Integration with wagmi

Combine with wagmi for a complete wallet experience:

Balance Formatting

The hook automatically formats balances for display:

Error Handling

Best Practices

Performance and UX Tips:
  1. Choose refresh intervals wisely - Too frequent refreshes waste resources. 10-30 seconds is usually sufficient.
  2. Use enabled for optimization - Disable fetching when the component is not visible or wallet is not connected.
  3. Handle loading gracefully - Show previous balance while refreshing (stale-while-revalidate pattern).
  4. Clear data on wallet change - The hook automatically clears data when walletAddress changes.
  5. Manual refetch clears interval - When you call refetch(), the auto-refresh timer resets to prevent overlapping requests.

Next Steps

useQuote

Fetch bridge quotes

useTransactionStatus

Track transaction progress