Initiates a withdrawal to move funds from the Spark network to an on-chain Bitcoin address via the SparkWallet.
Method Signature
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
The Bitcoin address where the funds should be sent
The desired speed of the exit (FAST, MEDIUM, SLOW)
The amount in satoshis to withdraw (if not specified, withdraws all available funds)
feeQuote
WithdrawalFeeQuote
required
The fee quote object returned by getWithdrawalFeeQuote (must be used before expiry)
deductFeeFromWithdrawalAmount
When true, fees are deducted from withdrawal amount; when false, from remaining wallet balance (default: true)
Returns
request
CoopExitRequest | null | undefined
required
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);