Skip to main content
Methods for withdrawing funds from Spark back to Bitcoin L1.

withdraw(params)

Initiates a withdrawal to move funds from the Spark network to an on-chain Bitcoin address.
interface WithdrawParams {
  onchainAddress: string;
  exitSpeed: ExitSpeed;
  amountSats?: number;
  feeQuote: WithdrawalFeeQuote; // returned by getWithdrawalFeeQuote
  deductFeeFromWithdrawalAmount?: boolean; // default: true
}

async withdraw(params: WithdrawParams): Promise<CoopExitRequest | null | undefined>
Parameters:
  • params: An object with the following properties:
    • onchainAddress: (Required) The Bitcoin address where the funds should be sent.
    • exitSpeed: (Required) The desired speed of the exit (FAST, MEDIUM, SLOW).
    • amountSats: (Optional) The amount in satoshis to withdraw. If not specified, attempts to withdraw all available funds.
    • feeQuote: (Required) The fee quote object returned by getWithdrawalFeeQuote. Must be used before it expires.
    • deductFeeFromWithdrawalAmount: (Optional, default: true) When true, fees are deducted from the withdrawal amount. When false, fees are deducted from the remaining wallet balance.
Returns:
  • Promise<CoopExitRequest | null | undefined>: The withdrawal request details, or null/undefined if the request cannot be completed.
Example:
// 1) Fetch a fee quote
const feeQuote = await wallet.getWithdrawalFeeQuote({
  amountSats: 17000,
  withdrawalAddress:
    "bcrt1pf8hed85p94emupfpfhq2g0p5c40cgzqs4agvvfmeuy32nxeh549syu2lwf",
});

// 2) Use the quote before it expires to create the withdrawal
const withdraw_result = await wallet.withdraw({
  onchainAddress:
    "bcrt1pf8hed85p94emupfpfhq2g0p5c40cgzqs4agvvfmeuy32nxeh549syu2lwf",
  amountSats: 17000,
  exitSpeed: ExitSpeed.MEDIUM, // Or ExitSpeed.FAST, ExitSpeed.SLOW
  feeQuote,
  deductFeeFromWithdrawalAmount: true,
});
console.log("Withdraw Result:", withdraw_result);

getWithdrawalFeeQuote(params)

Gets a fee quote for a cooperative exit (on-chain withdrawal). The quote includes options for different speeds and an expiry time and must be passed to withdraw before it expires.
async getWithdrawalFeeQuote({
  amountSats,
  withdrawalAddress,
}: {
  amountSats: number;
  withdrawalAddress: string;
}): Promise<WithdrawalFeeQuote | null>
Parameters:
  • params: Object containing:
    • amountSats: The amount in satoshis to withdraw.
    • withdrawalAddress: The Bitcoin address where the funds should be sent.
Returns:
  • Promise<WithdrawalFeeQuote | null>: A fee quote for the withdrawal, or null if not available.

getCoopExitRequest(id: string)

Gets a cooperative exit request by ID.
async getCoopExitRequest(id: string): Promise<CoopExitRequest | null>
Parameters:
  • id: The ID of the cooperative exit request.
Returns:
  • Promise<CoopExitRequest | null>: The cooperative exit request details or null if not found.