spark_getBalance
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
A bigint
representing the total amount of Bitcoin in satoshis
tokenBalances
A Map of token balances, where each entry contains:
balance
: Abigint
representing the token amounttokenInfo
: an object providing information about the specific token the wallet is holding:tokenPublicKey
: a string representing the token public keytokenName
: a string representing the token nametokenTicker
: a string representing the token tickerdecimals
: a string representing the decimals supportedmaxSupply
: a string representing the max token supply
Last updated