Demos
Token Balance
Token Balance
This example shows how to get an ERC20 token balance.
Lookup token balance
Loading...
The useBalance
hook
The useBalance
hook is used to fetch an ERC20 token balance.
This hook accepts three arguments:
address
: the account address for which we want to check the balance.token
(optional): the ERC20 contract address. If no token is provided, the hook will look up the balance for the network's native currency.watch
(optional): refresh data at every block.
_10const { data, error, isLoading } = useBalance({_10 address,_10 watch: true,_10});
The data
returned by the hook can be formatted as follows:
_10<p>Balance: {data.formatted} {data.symbol}</p>