Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

useWalletAssets

Get token balances for the current wallet.

Usage

import { useWalletAssets } from '@openfort/react';
import { formatUnits } from 'viem';
 
function WalletAssets() {
  const { data: assets, isLoading, error } = useWalletAssets();
 
  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;
 
  return (
    <ul>
      {assets?.map((asset) => (
        <li key={asset.address}>
          {formatUnits(asset.balance, asset.metadata?.decimals ?? 18)} {asset.metadata?.symbol}
        </li>
      ))}
    </ul>
  );
}

Return type

type UseWalletAssetsReturn = {
  data: Asset[] | null
  isLoading: boolean
  isError: boolean
  isSuccess: boolean
  isIdle: boolean  // True when wallet client is not available
  error?: OpenfortError
  refetch(): Promise<Asset[]>
}
 
type Asset = {
  type: 'native' | 'erc20'
  address: string | 'native'
  balance: bigint
  metadata?: {
    name?: string
    symbol?: string
    decimals?: number
    fiat?: {
      value: number
      currency: string
    }
  }
  raw: object  // Raw asset data from provider
}

Parameters

type WalletAssetsHookOptions = {
  assets?: OpenfortWalletConfig['assets']  // Additional assets to track per chain
  staleTime?: number  // Cache duration in ms (default: 30000)
}
 
// Format: { [chainId: number]: string[] }
// For USDC on mainnet: { 1: ['0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'] }
Copyright © 2023-present Alamas Labs, Inc