
Get Issuer Token Balance
Check the token balance for a specific Spark address or your own issuer wallet.getIssuerTokenBalance(sparkAddress?)
Gets the token balance of the wallet.
Balance Examples
Check Issuer Balance
Check User Balance
Convert Base Units to Tokens
Get Wallet Balance
Get the complete balance of your wallet including Bitcoin and all token balances.getBalance()
Gets the current balance of the wallet.
Wallet Balance Examples
Basic Balance Check
Display All Token Balances
Check Specific Token Balance
Balance Monitoring
Set up real-time monitoring for balance changes.Event-Based Monitoring
Periodic Balance Checks
Best Practices
Balance Management
- Cache Balances: Store balance data locally to avoid repeated API calls
- Handle BigInt: Always use BigInt for balance calculations to prevent precision loss
- Convert for Display: Convert base units to display units using token decimals
- Monitor Changes: Use event listeners to track balance changes in real-time
Error Handling
- Network Issues: Implement retry logic for balance queries
- Invalid Addresses: Validate Spark addresses before checking balances
- Missing Tokens: Handle cases where tokens don’t exist in wallet
Performance
- Batch Checks: When checking multiple addresses, consider batching requests
- Selective Updates: Only check balances when necessary to reduce API calls
- Local Storage: Cache balance data for better user experience
