Understanding Cooperative Exits

Exiting Bitcoin to L1 involves a cooperative exit. This requires coordination between your wallet and the SSP to process your withdrawal efficiently. It’s the preferred method because:
  • Lower fees than unilateral exits
  • It’s faster (no timelocks)

Initiating the Withdraw

// 1) Get a fee quote (quote includes expiry)
const feeQuote = await wallet.getWithdrawalFeeQuote({
  amountSats: 17000,
  withdrawalAddress:
    "bcrt1pf8hed85p94emupfpfhq2g0p5c40cgzqs4agvvfmeuy32nxeh549syu2lwf",
});

// 2) Use the quote before it expires when calling withdraw
const withdraw_result = await wallet.withdraw({
  onchainAddress:
    "bcrt1pf8hed85p94emupfpfhq2g0p5c40cgzqs4agvvfmeuy32nxeh549syu2lwf",
  amountSats: 17000,
  exitSpeed: ExitSpeed.MEDIUM,
  feeQuote,
  deductFeeFromWithdrawalAmount: true, // default
});
console.log("Withdraw Result:", withdraw_result);
The minimum amount to withdraw is 10,000 sats

Fee Considerations

  • Network fees are required for the Bitcoin transaction.
  • By default (deductFeeFromWithdrawalAmount = true), fees are deducted from amountSats. When set to false, fees are deducted from remaining wallet balance.
  • The total cost can include:
    • Bitcoin network fee
    • Spark service fee (if applicable, charged by the SSP)
    • Example: If amountSats is 10,000 sats, Bitcoin fees are 2,000 sats, and SSP fees are 1,000 sats, you’ll receive 7,000 sats at your L1 address (with default fee deduction).

Performance Note

  • For latency reasons, the SDK does not automatically fetch a fee quote during withdraw when one is not provided. Pre-fetch the quote with getWithdrawalFeeQuote and pass it to withdraw.

Best Practices

  • Verify the withdrawal address before confirming
  • Keep track of your exit transaction ID
  • Wait for sufficient confirmations

Common Issues

  • Network congestion delays
  • Address format issues
  • Insufficient balance for fees

Need Help?