useTokenBalance

Hook for fetching the balance a wallet has for a specific ERC20 token.

This hook is for custom ERC20 tokens. For native tokens such as Ether, use useBalance or useBalanceForAddress

Available to use on contracts that implement the ERC20 interface.

Example

import { useTokenBalance, useContract } from "@thirdweb-dev/react";
function App() {
const { contract } = useContract(contractAddress, "token");
const { data, isLoading, error } = useTokenBalance(
contract,
walletAddress,
);
}
function useTokenBalance(
contract: RequiredParam<TokenContract>,
walletAddress: RequiredParam<string>,
): UseQueryResult<
{
decimals: number;
displayValue: string;
name: string;
symbol: string;
value: BigNumber;
},
unknown
>;

Parameters

Instance of a TokenContract

Type

let contract: RequiredParam<TokenContract>;

Type

let walletAddress: RequiredParam<string>;

Returns

let returnType: UseQueryResult<
{
decimals: number;
displayValue: string;
name: string;
symbol: string;
value: BigNumber;
},
unknown
>;

Hook's data object includes the token balance for given wallet address