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
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;
// 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
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
}
// 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;
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
// 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
// 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;
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
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:
- Call
get_infoget_infogetInfogetInfogetInfogetInfogetInfoGetInfoGetInfowithensure_syncedensure_syncedensureSyncedensureSyncedensureSyncedensureSyncedensureSyncedEnsureSyncedEnsureSynced= false whenever you need to render the balance. - Subscribe to events and call
get_infoget_infogetInfogetInfogetInfogetInfogetInfoGetInfoGetInfoagain on eachSdkEvent::SyncedSdkEvent.SYNCEDSdkEvent.syncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEventSyncedSdkEvent.Syncedevent to fetch the latest balance. See Listening to events.
| Event | Description | UX Suggestion |
|---|---|---|
SdkEvent::SyncedSdkEvent.SYNCEDSdkEvent.syncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEvent.SyncedSdkEventSyncedSdkEvent.Synced | The 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.