WDK logoWDK documentation

Check Balances

Query native Spark balances and read-only account balances.

This guide explains how to read a native Spark balance, query a token balance, and check read-only account balances.

Native Spark Balance

You can read the account balance in satoshis using account.getBalance():

Native Spark Balance
const balance = await account.getBalance()
console.log('Balance:', balance, 'satoshis')
console.log('Balance in BTC:', Number(balance) / 100000000)

Balances are in satoshis (1 BTC = 100,000,000 satoshis).

If you configure sparkscan, account.getBalance() returns SparkScan's btcSoftBalanceSats value instead of the Spark SDK balance:

SparkScan Balance Polling
const wallet = new WalletManagerSpark(seedPhrase, {
  network: 'MAINNET',
  sparkscan: {
    apiKey: 'your-api-key-here',
  },
})

const account = await wallet.getAccount(0)
const balance = await account.getBalance()
console.log('SparkScan balance:', balance)

Token Balance

You can read a specific token balance using account.getTokenBalance():

Token Balance
const tokenBalance = await account.getTokenBalance('token_address...')
console.log('Token balance:', tokenBalance)

Read-Only Account Balances

  1. Construct a WalletAccountReadOnlySpark instance with the Spark address and optional config.
  2. Call readOnlyAccount.getBalance().

You can create a read-only account from a Spark address using the WalletAccountReadOnlySpark constructor:

Read-Only Account
import { WalletAccountReadOnlySpark } from '@tetherto/wdk-wallet-spark'

const readOnlyAccount = new WalletAccountReadOnlySpark('spark1...', {
  network: 'MAINNET'
})

You can read the native balance from that account using readOnlyAccount.getBalance():

Read-Only Native Balance
const balance = await readOnlyAccount.getBalance()
console.log('Read-only balance:', balance, 'satoshis')

The same sparkscan behavior applies to read-only accounts.

You can read a token balance on a read-only account using readOnlyAccount.getTokenBalance():

Read-Only Token Balance
const tokenBalance = await readOnlyAccount.getTokenBalance('token_address...')
console.log('Read-only token balance:', tokenBalance)

You can also obtain a read-only handle from an owned account with account.toReadOnlyAccount().

Next Steps

With balances verified, learn how to send Spark and transfer tokens.

On this page