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

# Withdraw from Reward Wallet

> Initiate a withdrawal from reward wallet to external wallet address

## Overview

Withdraw accumulated rewards to a registered external wallet. The withdrawal is processed on-chain on the Linea network. The net amount received equals the requested amount minus network gas fees.

**Prerequisites:**

* User must have registered external wallet (completed delegation)
* Reward wallet must have sufficient balance
* Rewards must be vested and withdrawable

## Authentication

<ParamField header="x-client-key" type="string" required>
  Your public API client key
</ParamField>

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

## Query Parameters

<ParamField query="x-us-env" type="boolean" default={false}>
  Route to US backend environment
</ParamField>

## Request Body

<ParamField body="amount" type="string" required>
  Amount to withdraw in USDC (decimal string)
</ParamField>

## Response

<ResponseField name="txHash" type="string">
  Blockchain transaction hash for tracking on Linea network
</ResponseField>

<ResponseExample>
  ```json 200 - Success theme={null}
  {
    "txHash": "0xb92de09d893e8162b0861c0f7321f68df02212efbc58f208839ae3f176d89638"
  }
  ```

  ```json 400 - Bad Request theme={null}
  {
    "message": "Insufficient reward balance"
  }
  ```

  ```json 422 - Validation Error theme={null}
  {
    "message": "amount must be a positive number"
  }
  ```
</ResponseExample>

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://dev.api.baanx.com/v1/wallet/reward/withdraw" \
    -H "x-client-key: YOUR_CLIENT_KEY" \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"amount": "25.00"}'
  ```

  ```python Python theme={null}
  import requests

  url = "https://dev.api.baanx.com/v1/wallet/reward/withdraw"
  headers = {
      "x-client-key": "YOUR_CLIENT_KEY",
      "Authorization": "Bearer YOUR_ACCESS_TOKEN",
      "Content-Type": "application/json"
  }
  data = {"amount": "25.00"}

  response = requests.post(url, headers=headers, json=data)

  if response.status_code == 200:
      result = response.json()
      print(f"Withdrawal initiated: {result['txHash']}")
      print(f"Track on Linea: https://lineascan.build/tx/{result['txHash']}")
  ```

  ```typescript TypeScript theme={null}
  interface WithdrawalResponse {
    txHash: string;
  }

  async function withdrawRewards(amount: string): Promise<string> {
    const response = await fetch(
      'https://dev.api.baanx.com/v1/wallet/reward/withdraw',
      {
        method: 'POST',
        headers: {
          'x-client-key': 'YOUR_CLIENT_KEY',
          'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({ amount })
      }
    );

    if (!response.ok) throw new Error('Withdrawal failed');

    const data: WithdrawalResponse = await response.json();
    return data.txHash;
  }
  ```
</CodeGroup>

## Complete Withdrawal Flow

<Steps>
  <Step title="Check Reward Balance">
    ```javascript theme={null}
    const wallet = await fetch('/v1/wallet/reward').then(r => r.json());
    const balance = parseFloat(wallet.balance);
    ```
  </Step>

  <Step title="Estimate Fees">
    ```javascript theme={null}
    const fees = await fetch('/v1/wallet/reward/withdraw-estimation')
      .then(r => r.json());
    const feeUSDC = parseFloat(fees.usdc);
    ```
  </Step>

  <Step title="Calculate Net Amount">
    ```javascript theme={null}
    const netAmount = balance - feeUSDC;
    console.log(`You will receive: ${netAmount.toFixed(2)} USDC`);
    ```
  </Step>

  <Step title="Initiate Withdrawal">
    ```javascript theme={null}
    const { txHash } = await fetch('/v1/wallet/reward/withdraw', {
      method: 'POST',
      body: JSON.stringify({ amount: balance.toString() })
    }).then(r => r.json());
    ```
  </Step>

  <Step title="Monitor Transaction">
    ```javascript theme={null}
    const explorerUrl = `https://lineascan.build/tx/${txHash}`;
    console.log(`Track withdrawal: ${explorerUrl}`);
    ```
  </Step>
</Steps>

## Important Notes

<Warning>
  **Balance Requirements**: Withdrawal amount plus fees must not exceed available reward balance.
</Warning>

<Note>
  **Vesting Periods**: Some rewards may have vesting periods before withdrawal is allowed. Check `isWithdrawable` flag on the reward wallet.
</Note>

<Tip>
  **Transaction Monitoring**: Use the returned `txHash` to track status. Linea confirmations typically take 1-3 minutes.
</Tip>

## Related Endpoints

* [Estimate Reward Withdrawal Fees](/api-reference/wallet/reward-withdraw-estimation)
* [Get Reward Wallet Balance](/api-reference/wallet/reward)
* [Get Wallet History](/api-reference/wallet/history)
