Skip to content

Querying Balances ​

The SDK refreshes shielded balances on demand with refreshBalances and stores the result in the configured storage adapter (IndexedDB in the browser, in-memory on the server).

Refreshing Balances ​

ts
import { refreshBalances } from "@0xcurvy/curvy-sdk/actions";

await refreshBalances({ config });

Pass accountId to target a specific account, or omit it to use the active account.

Keeping Balances Current ​

Notes sent to the account arrive without any action on its side. To find them while an app is open, start a background refresh: it scans every 30 seconds until you stop it.

ts
import { startBalanceRefresh } from "@0xcurvy/curvy-sdk/actions";

const stop = startBalanceRefresh({ config, runImmediately: true });

// Later, for example when the page is hidden or the user signs out:
stop();

Runs never overlap. A run joins a refresh already in progress, and runs are skipped while a plan executes. Pass signal to stop the loop and cancel its scan together, for example when a session ends. A config runs one loop; starting again replaces it. See startBalanceRefresh.

Reading Balances ​

ts
import { getBalances } from "@0xcurvy/curvy-sdk/actions";

const cachedBalances = await getBalances({ config });
const freshBalances = await getBalances({ config, cached: false });

console.log(`Found ${cachedBalances.length} balance(s).`);

getBalances returns cached balances by default. Pass cached: false to refresh from chain first (equivalent to calling refreshBalances beforehand).

Aggregated totals per currency are available from the storage surface:

ts
const activeAccountId = config.state.activeAccountId;
if (!activeAccountId) throw new Error("No active account");

const totals = await config.storage.getTotals(activeAccountId, config.state.environment);