useBalance hook provides a single interface to fetch the balance of any asset on the Stellar network. It automatically detects the asset type and returns a normalized object, so your components do not need to handle different decimal logic for different asset classes.
Asset ID Formats
You can pass three types of identifiers to theassetId parameter:
- native: Fetches the XLM balance.
- CODE:ISSUER: Fetches a classic Stellar asset (e.g.,
USDC:GA5Z...). - C…: Fetches the balance from a Soroban token contract.
Usage
Normalization Logic
The hook performs the following background tasks:- Decimal Handling: Classic assets are always treated as 7 decimals. Soroban assets are queried for their specific decimal count at runtime.
- BigInt Safety: The
rawbalance is always returned as abigintto prevent precision loss during mathematical operations. - Smart Caching: Uses TanStack Query to ensure multiple components requesting the same balance do not trigger redundant network calls.
Parameters
address: TheG...orC...address whose balance you want to check.assetId: The identifier for the asset.options: Standard query options, includingenabledto defer the fetch.
Return Value
The hook returns a query result object wheredata contains:
raw: The balance in the smallest unit (stroops or bits) as abigint.formatted: A human-readable string with the decimal point in the correct place.decimals: The number of decimal places used by the asset.

