Skip to Content
HooksuseSbtcBalance / useStxBalance

useSbtcBalance & useStxBalance

Live balance hooks. Both take an address (or null/undefined to stay idle) and an optional polling interval, and expose a raw bigint, a formatted string, loading/refreshing flags, an error, and a manual refresh().

useSbtcBalance

Reads the SIP-010 sBTC token balance for address.

function useSbtcBalance( address: string | null | undefined, options?: { pollIntervalMs?: number }, ): UseSbtcBalanceResult;
FieldTypeDescription
satsbigint | nullsBTC balance in satoshis (1 sBTC = 1e8 sats), or null before first load.
btcstring | nullFormatted BTC string, e.g. '0.0012 BTC'.
isLoadingbooleanTrue until the first load settles.
isRefreshingbooleanTrue during a refresh() after data exists.
errorSbtcError | nullLast fetch error.
refresh()() => voidRe-fetch now.

useStxBalance

Reads the account’s STX balance.

function useStxBalance( address: string | null | undefined, options?: { pollIntervalMs?: number }, ): UseStxBalanceResult;
FieldTypeDescription
microStxbigint | nullTotal STX balance in µSTX, or null before first load.
stxstring | nullFormatted STX string, e.g. '1.234567 STX'.
isLoadingbooleanTrue until the first load settles.
isRefreshingbooleanTrue during a refresh().
errorSbtcError | nullLast fetch error.
refresh()() => voidRe-fetch now.

Example

import { useStacksWallet, useSbtcBalance, useStxBalance } from '@baoku26/sbtc-sdk'; function Balances() { const { address } = useStacksWallet(); const sbtc = useSbtcBalance(address); // null address → idle, no fetch const stx = useStxBalance(address, { pollIntervalMs: 30_000 }); return ( <> <p>sBTC: {sbtc.isLoading ? '…' : (sbtc.btc ?? '—')}</p> <p>STX: {stx.isLoading ? '…' : (stx.stx ?? '—')}</p> <button onClick={sbtc.refresh} disabled={sbtc.isRefreshing}>Refresh</button> </> ); }

Passing null/undefined as the address keeps the hook idle (no request) — convenient before a wallet exists. For raw-value formatting, see the formatSats / formatBtc / satsToBtc / btcToSats utilities exported from @baoku26/sbtc-sdk.

Last updated on