Starknet testnet is migrating to Sepolia. Read more.

Hooks
query
useBalance

useBalance

Fetch a block.

Usage


_13
import { useAccount, useBalance } from "@starknet-react/core";
_13
_13
export default function Component() {
_13
const { address } = useAccount();
_13
const { isLoading, isError, error, data } = useBalance({
_13
address,
_13
watch: true
_13
})
_13
_13
if (isLoading) return <div>Loading ...</div>;
_13
if (isError || !data) return <div>{error?.message}</div>;
_13
return <div>{data.value.toString()}{data.symbol}</div>
_13
}

Options

  • token?: string
    • The ERC20 contract's address. Defaults to the native token.
  • address?: string
    • The target address.
    • If the value is undefined, no call is made.
  • watch?: boolean
    • If true, refresh the balance at every block.

Returns

  • data?: { decimals: number, symbol: string, formatted: string, value: bigint }
    • The address's balance.
    • decimals is the number of ERC20 decimals.
    • symbol is the ERC20 symbol.
    • formatted is the formatted balance.
    • value is the raw balance.