Fetch the balance of a wallet in native currency or for a specific token. Leave tokenAddress undefined to fetch the native token balance.
tokenAddress
import { useWalletBalance } from "thirdweb/react"; const { data, isLoading, isError } = useWalletBalance({ chain, address, client,});console.log("balance", data?.displayValue, data?.symbol);
import { useWalletBalance } from "thirdweb/react"; const tokenAddress = "0x..."; // the ERC20 token address const { data, isLoading, isError } = useWalletBalance({ chain, address, client, tokenAddress,});console.log("balance", data?.displayValue, data?.symbol);
function useWalletBalance( options: { address: undefined | string; chain: undefined | Readonly<ChainOptions & { rpc: string }>; client: ThirdwebClient; tokenAddress?: string; }, queryOptions?: UseWalletBalanceQueryOptions,): UseQueryResult<GetBalanceResult>;
GetWalletBalanceOptions - The options for fetching the wallet balance.
let options: { address: undefined | string; chain: undefined | Readonly<ChainOptions & { rpc: string }>; client: ThirdwebClient; tokenAddress?: string;};
let queryOptions: UseWalletBalanceQueryOptions;
let returnType: UseQueryResult<GetBalanceResult>;
GetWalletBalanceResult The result of the query.