Skip to main content

useBalance

Hook for getting a wallet's current balance of an ERC20 token, (including native tokens such as Ether).

import { useBalance } from "@thirdweb-dev/react";

Usage

Provide the token contract address as the argument.

import { useBalance } from "@thirdweb-dev/react";

// Your ERC20 token smart contract address
const tokenAddress = "{{token_address}}";

function App() {
const { data, isLoading } = useBalance(tokenAddress);
}

Configuration

To load the balance of the native token to your chain, such as Ether on Ethereum, import the NATIVE_TOKEN_ADDRESS constant from @thirdweb-dev/sdk.

import { useBalance } from "@thirdweb-dev/react";
import { NATIVE_TOKEN_ADDRESS } from "@thirdweb-dev/sdk";

function App() {
const { data, isLoading } = useBalance(NATIVE_TOKEN_ADDRESS);
}

Return Value

The hook's data property, once loaded, contains the following properties:

{
symbol: string;
value: BigNumber;
name: string;
decimals: number;
displayValue: string;
} | undefined>;