useBalance

Hook for getting a wallet's current balance of native or (optional) ERC20 token balance

Example

get the balance of the native token

import { useBalance } from "@thirdweb-dev/react";
function App() {
const { data, isLoading } = useBalance();
}

get the balance of any other token

import { useBalance } from "@thirdweb-dev/react";
function App() {
const { data, isLoading } = useBalance(tokenAddress);
}
function useBalance(
tokenAddress?: string,
): UseQueryResult<
| {
decimals: number;
displayValue: string;
name: string;
symbol: string;
value: BigNumber;
}
| undefined,
unknown
>;

Parameters

The address of the token contract, if not provided, it defaults to the native token

Type

let tokenAddress: string;

Returns

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

The hook's data property contains the token's balance in the value property as a BigNumber object.