Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Getting the SDK info API docs

Once connected, you can retrieve the current state of the SDK at any time using get_infoget_infogetInfogetInfogetInfogetInfogetInfoGetInfoGetInfo. This returns:

  • Spark identity public key - The wallet's unique identity on the Spark network as a hex string
  • Bitcoin balance - The balance in satoshis
  • Token balances - Balances of any tokens held in the wallet
Rust
let info = sdk
    .get_info(GetInfoRequest {
        // ensure_synced: true will ensure the SDK is synced with the Spark network
        // before returning the balance
        ensure_synced: Some(false),
    })
    .await?;
let identity_pubkey = &info.identity_pubkey;
let balance_sats = info.balance_sats;
Swift
// ensureSynced: true will ensure the SDK is synced with the Spark network
// before returning the balance
let info = try await sdk.getInfo(
    request: GetInfoRequest(
        ensureSynced: false
    ))
let identityPubkey = info.identityPubkey
let balanceSats = info.balanceSats
Kotlin
try {
    // ensureSynced: true will ensure the SDK is synced with the Spark network
    // before returning the balance
    val info = sdk.getInfo(GetInfoRequest(false))
    val identityPubkey = info.identityPubkey
    val balanceSats = info.balanceSats
} catch (e: Exception) {
    // handle error
}
C#
// ensureSynced: true will ensure the SDK is synced with the Spark network
// before returning the balance
var info = await sdk.GetInfo(request: new GetInfoRequest(ensureSynced: false));
var identityPubkey = info.identityPubkey;
var balanceSats = info.balanceSats;
Javascript
const info = await sdk.getInfo({
  // ensureSynced: true will ensure the SDK is synced with the Spark network
  // before returning the balance
  ensureSynced: false
})
const identityPubkey = info.identityPubkey
const balanceSats = info.balanceSats
React Native
// ensureSynced: true will ensure the SDK is synced with the Spark network
// before returning the balance
const info = await sdk.getInfo({
  ensureSynced: false
})
const identityPubkey = info.identityPubkey
const balanceSats = info.balanceSats
Flutter
// ensureSynced: true will ensure the SDK is synced with the Spark network
// before returning the balance
final info = await sdk.getInfo(request: GetInfoRequest(ensureSynced: false));
final identityPubkey = info.identityPubkey;
final balanceSats = info.balanceSats;
Python
try:
    # ensure_synced: True will ensure the SDK is synced with the Spark network
    # before returning the balance
    info = await sdk.get_info(request=GetInfoRequest(ensure_synced=False))
    identity_pubkey = info.identity_pubkey
    balance_sats = info.balance_sats
except Exception as error:
    logging.error(error)
    raise
Go
ensureSynced := false
info, err := sdk.GetInfo(breez_sdk_spark.GetInfoRequest{
	// EnsureSynced: true will ensure the SDK is synced with the Spark network
	// before returning the balance
	EnsureSynced: &ensureSynced,
})

if err != nil {
	var sdkErr *breez_sdk_spark.SdkError
	if errors.As(err, &sdkErr) {
		// Handle SdkError - can inspect specific variants if needed
		// e.g., switch on sdkErr variant for InsufficientFunds, NetworkError, etc.
	}
	return err
}

identityPubkey := info.IdentityPubkey
balanceSats := info.BalanceSats
log.Printf("Identity pubkey: %v, Balance: %v sats", identityPubkey, balanceSats)

Fetching the balance

The SDK keeps a cached balance in local storage and get_infoget_infogetInfogetInfogetInfogetInfogetInfoGetInfoGetInfo reads from this cache for a low-latency response. The cache is refreshed automatically by the SDK's background sync.

The recommended pattern is:

  1. Call get_infoget_infogetInfogetInfogetInfogetInfogetInfoGetInfoGetInfo with ensure_syncedensure_syncedensureSyncedensureSyncedensureSyncedensureSyncedensureSyncedEnsureSyncedEnsureSynced = false whenever you need to render the balance.
  2. Subscribe to events and call get_infoget_infogetInfogetInfogetInfogetInfogetInfoGetInfoGetInfo again on each SdkEvent::SyncedSdkEvent.SYNCEDSdkEvent.syncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEventSyncedSdkEvent.Synced event to fetch the latest balance. See Listening to events.
EventDescriptionUX Suggestion
SdkEvent::SyncedSdkEvent.SYNCEDSdkEvent.syncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEventSyncedSdkEvent.SyncedThe SDK has synced with the network in the background.Call get_infoget_infogetInfogetInfogetInfogetInfogetInfoGetInfoGetInfo to refresh the displayed balance, and refresh the payments list. See listing payments.

Developer note

ensure_syncedensure_syncedensureSyncedensureSyncedensureSyncedensureSyncedensureSyncedEnsureSyncedEnsureSynced = true blocks until the SDK's initial sync after connectconnectconnectconnectconnectconnectconnectConnectConnect completes. This is useful for short-lived scripts that connect, read the balance once, and disconnect. It is not a "force a fresh sync now" call. In long-running applications, prefer ensure_syncedensure_syncedensureSyncedensureSyncedensureSyncedensureSyncedensureSyncedEnsureSyncedEnsureSynced = false combined with the SdkEvent::SyncedSdkEvent.SYNCEDSdkEvent.syncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEventSyncedSdkEvent.Synced event listener pattern above.