QubicTypeScript

useBalance

Fetches the QUBIC balance for a single identity, with optional polling.

useBalance queries the live API for the balance of one identity. Pass undefined as the identity to skip the fetch (useful when the address isn't known yet, such as before a wallet connects).

useBalance(identity, options?)

import { useBalance } from "@qubic.org/react"
import { useWallet } from "@qubic.org/react"

function WalletBalance() {
  const { account } = useWallet()
  const { data, isLoading, error } = useBalance(account?.identity, {
    refetchInterval: 10_000,
  })

  if (!account) return <p>Not connected</p>
  if (isLoading) return <p>Loading...</p>
  if (error) return <p>Error: {error.message}</p>

  // QubicBalance.balance is a bigint — format it for display
  const formatted = (data.balance / 1_000_000n).toLocaleString()

  return <p>Balance: {formatted} QUBIC</p>
}

Parameters

NameTypeDescription
identityIdentity | string | undefinedThe Qubic identity to query. Pass undefined to skip the fetch.
options.refetchIntervalnumber | falsePolling interval in milliseconds. Pass false to disable.

Returns

FieldTypeDescription
dataQubicBalance | undefinedBalance data, or undefined while loading.
data.idstringThe queried identity.
data.balancebigintCurrent balance in raw units.
data.validForTicknumberThe tick at which this balance snapshot was taken.
data.latestIncomingTransferTicknumberTick of the most recent incoming transfer.
data.latestOutgoingTransferTicknumberTick of the most recent outgoing transfer.
data.incomingAmountbigintTotal amount received.
data.outgoingAmountbigintTotal amount sent.
data.numberOfIncomingTransfersnumberTotal incoming transfer count.
data.numberOfOutgoingTransfersnumberTotal outgoing transfer count.
isLoadingbooleanTrue while the first fetch is in progress.
errorQubicRpcError | nullNetwork or parse error.

On this page