WDK logoWDK documentation
StartWalletsDeFi & FiatAI & CLITools

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

  1. Call account.getSingleUseDepositAddress().
  2. Send Bitcoin to the returned on-chain address and wait for confirmation.

You can generate a one-time Bitcoin deposit address using account.getSingleUseDepositAddress():

Single-Use Deposit Address
const depositAddress = await account.getSingleUseDepositAddress()
console.log('Send Bitcoin to:', depositAddress)

Claim Deposits

  1. Identify the Bitcoin transaction id that funded the deposit.
  2. Call account.claimDeposit() with that id.

You can credit the wallet after the deposit confirms using account.claimDeposit():

Claim Single-Use Deposit
const txId = 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16'
const walletLeaves = await account.claimDeposit(txId)
console.log('Deposit claimed:', walletLeaves)

1. (optional) Use a static deposit address

Get a reusable Bitcoin address with account.getStaticDepositAddress(). After the deposit confirms, identify the output paying this address and verify its amount in satoshis.

Request a claim quote. The example uses the transaction ID, output index and value that your application verified against the Bitcoin transaction.

Quote a Static Deposit Claim
const quote = await account.getClaimStaticDepositQuote({
  txId: verifiedDeposit.txId,
  outputIndex: verifiedDeposit.outputIndex,
  depositAmountSats: verifiedDeposit.amountSats
})

if (quote.transactionId !== verifiedDeposit.txId ||
    quote.outputIndex !== verifiedDeposit.outputIndex ||
    !Number.isSafeInteger(quote.creditAmountSats) ||
    quote.creditAmountSats <= 0 ||
    quote.creditAmountSats > verifiedDeposit.amountSats) {
  throw new Error('Claim quote does not match the verified deposit')
}

console.log('Credit in satoshis:', quote.creditAmountSats)
console.log('Claim fee in satoshis:', quote.claimFeeSats)

The displayed fee depends on the output amount you supplied. At claim time the SDK reads the Bitcoin output value and subtracts the freshly quoted credit to check the fee ceiling. The final credit can differ from the preview.

Claiming gives the Spark Service Provider the deposit's secret key and cannot be undone. The claim selects the first output paying any of the account's static deposit addresses. Use this flow for a transaction with one such output.

Pass the fee ceiling your caller approved when invoking claimStaticDeposit(). The returned transfer ID is a Spark identifier.

Claim With an Approved Fee Cap
if (!Number.isSafeInteger(approvedMaxFeeSats) || approvedMaxFeeSats < 0) {
  throw new Error('Provide an approved fee cap in whole satoshis')
}

const { transferId } = await account.claimStaticDeposit(verifiedDeposit.txId, {
  maxFeeSats: approvedMaxFeeSats
})
console.log('Spark transfer ID:', transferId)

If the fresh fee exceeds the cap, the claim throws StaticDepositFeeExceededError. Review the new fee with the caller before retrying.

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():

Query Static Deposit Addresses
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():

Query UTXOs
const result = await account.getUtxosForDepositAddress({
  depositAddress: 'bc1q...'
})
console.log('Confirmed UTXOs:', result.utxos)
console.log('Offset:', result.offset)

Withdraw to Bitcoin Layer 1

  1. Choose a Bitcoin onchainAddress and amountSats.
  2. Set withdrawMaxFee when creating the wallet if you need a quoted-fee limit, in satoshis.
  3. Request a cooperative exit quote with account.quoteWithdraw().
  4. Call account.withdraw() with the destination, amount, and exit speed.

You can request a withdrawal fee quote using account.quoteWithdraw():

Quote Withdrawal
const feeQuote = await account.quoteWithdraw({
  withdrawalAddress: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
  amountSats: 100000
})
console.log('Withdrawal fee quote:', feeQuote)

You can initiate the withdrawal using account.withdraw():

Withdraw to On-Chain Bitcoin
const withdrawal = await account.withdraw({
  onchainAddress: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
  amountSats: 100000,
  exitSpeed: 'MEDIUM'
})
console.log('Withdrawal request:', withdrawal)

withdraw() fetches a new quote and checks the selected speed's L1 broadcast fee plus user fee against withdrawMaxFee. A greater fee throws MaximumFeeExceededError; equality is allowed. The earlier quote is for inspection and is not the quote used for this check.

Next Steps

Learn how to handle errors and follow operational best practices.

On this page