Get your current Bitcoin balance and token holdings in your Spark wallet.getBalance()Gets the current balance of the wallet, including Bitcoin balance and token balances.
Track all incoming and outgoing transfers for your wallet with pagination support.getTransfers(limit?, offset?)Gets all transfers for the wallet with optional pagination.
getTransfers() includes Spark transfers, Lightning sends/receives, and cooperative exits. For token transaction details (e.g., sender address), use queryTokenTransactions().
Copy
Ask AI
// Get first 20 transfersconst transfers = await wallet.getTransfers();console.log("Transfers:", transfers.transfers);// Get next 10 transfers with paginationconst nextTransfers = await wallet.getTransfers(10, 20);console.log("Next page:", nextTransfers.transfers);// Get transfers from the last 24 hoursconst yesterday = new Date(Date.now() - 24 * 60 * 60 * 1000);const recentTransfers = await wallet.getTransfers(50, 0, yesterday);
Monitor wallet activity in real-time using EventEmitter methods for instant updates.on(event, listener)Adds a listener for the specified event to monitor wallet activity.
Copy
Ask AI
// Listen for incoming transfer claimswallet.on("transfer:claimed", (transferId, updatedBalance) => { console.log(`Transfer ${transferId} claimed. New balance: ${updatedBalance}`);});// Listen for deposit confirmations (after 3 L1 confirmations)wallet.on("deposit:confirmed", (depositId, updatedBalance) => { console.log(`Deposit ${depositId} confirmed. New balance: ${updatedBalance}`);});
once(event, listener)Adds a one-time listener for the specified event.
Copy
Ask AI
// Listen for a single incoming transferwallet.once("transfer:claimed", (transferId, updatedBalance) => { console.log(`Transfer ${transferId} claimed! New balance: ${updatedBalance}`);});
Emitted when a pending L1 deposit becomes spendable
stream:connected
Emitted when the event stream connects
stream:disconnected
Emitted when the stream disconnects
stream:reconnecting
Emitted when attempting to reconnect
Events only fire for incoming funds. For outgoing operations (Lightning sends, withdrawals), poll the status using getLightningSendRequest() or getCoopExitRequest().
Monitor your wallet activity using the Sparkscan block explorer for a visual interface.
Sparkscan provides a web interface to view your wallet’s transaction history, balance, and activity without needing to implement the API calls yourself.