useWalletBalance

Fetch the balance of a wallet in native currency or for a specific token. Leave tokenAddress undefined to fetch the native token balance.

Example

Fetching the native token balance

import { useWalletBalance } from "thirdweb/react";
const { data, isLoading, isError } = useWalletBalance({
chain,
address,
client,
});
console.log("balance", data?.displayValue, data?.symbol);

Fetching a specific token balance

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<GetWalletBalanceResult>;

Parameters

GetWalletBalanceOptions - The options for fetching the wallet balance.

Type

let options: {
address: undefined | string;
chain: undefined | Readonly<ChainOptions & { rpc: string }>;
client: ThirdwebClient;
tokenAddress?: string;
};

Type

let queryOptions: UseWalletBalanceQueryOptions;

Returns

let returnType: UseQueryResult<GetWalletBalanceResult>;

GetWalletBalanceResult The result of the query.