balance

suspend fun balance(): WalletBalance

Current snapshot of every balance the SDK tracks for this wallet — unshielded NIGHT, shielded NIGHT, DUST, and the registration flag.

Sources (all kept fresh by the SDK; no consumer action required):

  • Unshielded NIGHT: BalanceRepository flow over the unshielded-tx subscription started at SDK-build time.

  • Shielded NIGHT: ShieldedBalanceTracker's cache, refreshed by the zswap-event subscription started at SDK-build time. Returns 0 until the first sync lands (a few hundred ms on localnet, a few seconds on PREPROD on first run).

  • DUST: DustRepository local replay state.

dustRegistered is a best-effort heuristic — true iff DUST 0. A fresh wallet that hasn't called MidnightSdk.registerForDustGeneration reports false here even with NIGHT funded, because the chain doesn't release spendable dust to an unregistered key.

For a forced resync (e.g. before a sequential tx or when the UI wants to skip the subscription's natural cadence), call refresh first.