> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spark.money/llms.txt
> Use this file to discover all available pages before exploring further.

# withdraw

> Withdraw to an on-chain Bitcoin address via cooperative exit.

Initiates a withdrawal to move funds from the Spark network to an on-chain Bitcoin address via the `SparkWallet`.

## Method Signature

```typescript theme={null}
interface WithdrawParams {
  onchainAddress: string;
  exitSpeed: ExitSpeed;
  feeQuote?: CoopExitFeeQuote;   // Deprecated: use feeQuoteId + feeAmountSats
  amountSats?: number;
  feeQuoteId?: string;           // ID from getWithdrawalFeeQuote
  feeAmountSats?: number;        // Fee amount based on exitSpeed
  deductFeeFromWithdrawalAmount?: boolean; // default: true
}

async withdraw(params: WithdrawParams): Promise<CoopExitRequest | null>
```

## Parameters

<ResponseField name="onchainAddress" type="string" required>
  The Bitcoin address where the funds should be sent
</ResponseField>

<ResponseField name="exitSpeed" type="ExitSpeed" required>
  The desired speed of the exit (`FAST`, `MEDIUM`, `SLOW`)
</ResponseField>

<ResponseField name="feeQuote" type="CoopExitFeeQuote">
  Deprecated. Use `feeQuoteId` and `feeAmountSats` instead.
</ResponseField>

<ResponseField name="amountSats" type="number">
  The amount in satoshis to withdraw (if not specified, withdraws all available funds)
</ResponseField>

<ResponseField name="feeQuoteId" type="string">
  The ID from the fee quote returned by `getWithdrawalFeeQuote`
</ResponseField>

<ResponseField name="feeAmountSats" type="number">
  The fee amount in satoshis based on the chosen `exitSpeed`
</ResponseField>

<ResponseField name="deductFeeFromWithdrawalAmount" type="boolean">
  When `true`, fees are deducted from withdrawal amount; when `false`, from remaining wallet balance (default: `true`)
</ResponseField>

## Returns

<ResponseField name="request" type="CoopExitRequest | null" required>
  The withdrawal request details, or null if the request cannot be completed
</ResponseField>

## Example

```typescript theme={null}
// 1) Fetch a fee quote
const feeQuote = await wallet.getWithdrawalFeeQuote({
  amountSats: 17000,
  withdrawalAddress: "bcrt1pf8hed85p94emupfpfhq2g0p5c40cgzqs4agvvfmeuy32nxeh549syu2lwf",
});

// 2) Calculate fee based on exit speed
const exitSpeed = ExitSpeed.MEDIUM;
let feeAmountSats: number;
switch (exitSpeed) {
  case ExitSpeed.FAST:
    feeAmountSats = (feeQuote.l1BroadcastFeeFast?.originalValue || 0) + 
                    (feeQuote.userFeeFast?.originalValue || 0);
    break;
  case ExitSpeed.MEDIUM:
    feeAmountSats = (feeQuote.l1BroadcastFeeMedium?.originalValue || 0) + 
                    (feeQuote.userFeeMedium?.originalValue || 0);
    break;
  case ExitSpeed.SLOW:
    feeAmountSats = (feeQuote.l1BroadcastFeeSlow?.originalValue || 0) + 
                    (feeQuote.userFeeSlow?.originalValue || 0);
    break;
}

// 3) Use the quote before it expires to create the withdrawal
const withdraw_result = await wallet.withdraw({
  onchainAddress: "bcrt1pf8hed85p94emupfpfhq2g0p5c40cgzqs4agvvfmeuy32nxeh549syu2lwf",
  amountSats: 17000,
  exitSpeed,
  feeQuoteId: feeQuote.id,
  feeAmountSats,
  deductFeeFromWithdrawalAmount: true,
});
console.log("Withdraw Result:", withdraw_result);
```
