spark_getBalance

This method is coming πŸ”œ

You can use the getBalance method to retrieve your user's Spark wallet balances, i.e. the amount of Bitcoin & BTKN tokens that their connected wallet's Spark address owns.

Your app must have first connected to the wallet and obtained account read permissions. No query parameters are required for the method:

import { request } from 'sats-connect';

const response = await request('spark_getBalance', undefined);

if (response.status === 'success') {
  console.log(response.result);
} else {
  console.error(response.error);
}

The getBalance method will not trigger any operation or prompt your user to sign any transaction. It will return an object representing the connected wallet's Spark Bitcoin & BTKN holdings:

balance
Description

balance

A bigint representing the total amount of Bitcoin in satoshis

tokenBalances

A Map of token balances, where each entry contains:

  • balance: A bigint representing the token amount

  • tokenInfo: an object providing information about the specific token the wallet is holding:

    • tokenPublicKey: a string representing the token public key

    • tokenName: a string representing the token name

    • tokenTicker: a string representing the token ticker

    • decimals: a string representing the decimals supported

    • maxSupply: a string representing the max token supply

Last updated