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)

Developer note

The SDK maintains a cached balance for fast responses and updates it on every change. The get_infoget_infogetInfogetInfogetInfogetInfogetInfoGetInfoGetInfo call returns the value from this cache to provide a low-latency user experience.

Right after startup, the cache may not yet reflect the latest state from the network. Depending on your use case you can use one of the following options to get the fully up to date balance:

  • If your application runs continuously in the background, call get_infoget_infogetInfogetInfogetInfogetInfogetInfoGetInfoGetInfo after each SdkEvent::SyncedSdkEvent.SYNCEDSdkEvent.syncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEventSyncedSdkEvent.Synced event.
  • If you're only briefly using the SDK to fetch the balance, call get_infoget_infogetInfogetInfogetInfogetInfogetInfoGetInfoGetInfo with ensure_syncedensure_syncedensureSyncedensureSyncedensureSyncedensureSyncedensureSyncedEnsureSyncedEnsureSynced set to true before disconnecting.