Skip to content

useBalance

Fetches the balance of a given address or the default account if no address is provided.

Import

ts
import { useBalance } from "@midl/react";

Example

tsx
function Balance() {
  const { balance, isLoading, error } = useBalance();

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return <div>Balance: {balance}</div>;
}

Parameters

NameTypeDescription
addressstring(optional) The address to fetch the balance for. If not provided, uses the default account.
queryUseQueryOptions(optional) Query options for react-query.
configConfig(optional) Config object to use instead of the one from context.

Returns

NameTypeDescription
balancenumberThe balance of the address (or 0 if not found).
...restobjectAdditional query state from useQuery.