Deposits and Withdrawals
Fund Spark from Bitcoin layer 1 and withdraw back on-chain.
This guide explains how to get a single-use deposit address, claim deposits, query static deposit addresses, query UTXOs for a deposit address, and withdraw to Bitcoin layer 1.
Get a Single-Use Deposit Address
- Call
account.getSingleUseDepositAddress(). - Send Bitcoin to the returned on-chain address and wait for confirmation.
You can generate a one-time Bitcoin deposit address using account.getSingleUseDepositAddress():
const depositAddress = await account.getSingleUseDepositAddress()
console.log('Send Bitcoin to:', depositAddress)Claim Deposits
- Identify the Bitcoin transaction id that funded the deposit.
- Call
account.claimDeposit()with that id.
You can credit the wallet after the deposit confirms using account.claimDeposit():
const txId = 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16'
const walletLeaves = await account.claimDeposit(txId)
console.log('Deposit claimed:', walletLeaves)1. (optional) Use a static deposit address
You can reuse one on-chain deposit address using account.getStaticDepositAddress(), then credit the wallet with account.claimStaticDeposit() after the Bitcoin transaction confirms:
const staticAddress = await account.getStaticDepositAddress()
console.log('Static deposit address:', staticAddress)
const staticLeaves = await account.claimStaticDeposit(
'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16'
)
console.log('Static deposit claimed:', staticLeaves)You can list unused single-use addresses with account.getUnusedDepositAddresses(). The method returns a paginated result with depositAddresses and offset fields.
Query Static Deposit Addresses
You can list all existing static deposit addresses using account.getStaticDepositAddresses():
const addresses = await account.getStaticDepositAddresses()
console.log('Static deposit addresses:', addresses)Query UTXOs for a Deposit Address
You can check confirmed UTXOs for a specific deposit address using account.getUtxosForDepositAddress():
const result = await account.getUtxosForDepositAddress({
depositAddress: 'bc1q...'
})
console.log('Confirmed UTXOs:', result.utxos)
console.log('Offset:', result.offset)Withdraw to Bitcoin Layer 1
- Choose a Bitcoin
onchainAddressandamountSats. - Request a cooperative exit quote with
account.quoteWithdraw(). - Call
account.withdraw()with the destination and amount.
You can request a withdrawal fee quote using account.quoteWithdraw():
const feeQuote = await account.quoteWithdraw({
withdrawalAddress: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
amountSats: 100000
})
console.log('Withdrawal fee quote:', feeQuote)You can initiate the withdrawal using account.withdraw():
const withdrawal = await account.withdraw({
onchainAddress: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
amountSats: 100000
})
console.log('Withdrawal request:', withdrawal)withdraw() accepts onchainAddress and amountSats. Run quoteWithdraw() first to understand the cooperative exit costs before initiating the withdrawal.
Next Steps
Learn how to handle errors and follow operational best practices.