> ## 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.

# Estimate Credit Withdrawal Fees

> Calculate network fees for withdrawing funds from the credit wallet

## Overview

This endpoint calculates the estimated gas fees for withdrawing funds from a credit wallet to an external wallet address. Network fees vary based on blockchain congestion and are deducted from the withdrawal amount. Always call this endpoint before initiating a withdrawal to inform users of the net amount they will receive.

**Use Cases:**

* Display estimated fees to users before withdrawal confirmation
* Calculate net amount user will receive after fees
* Compare fee estimates across different times to optimize for lower costs
* Provide transparency in withdrawal costs

**Network Support:**

* Currently supports **Linea network only**
* Returns fees in multiple denominations (wei, ETH, USDC)

## Authentication

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

<ParamField header="Authorization" type="string" required>
  Bearer token obtained from OAuth flow or direct login
</ParamField>

## Query Parameters

<ParamField query="x-us-env" type="boolean" default={false}>
  Set to `true` to route request to US backend environment (if available for your client)
</ParamField>

## Response

<ResponseField name="wei" type="string">
  Gas fee estimate in wei (smallest ETH unit)
</ResponseField>

<ResponseField name="eth" type="string">
  Gas fee estimate in ETH
</ResponseField>

<ResponseField name="usdc" type="string">
  Gas fee estimate converted to USDC at current exchange rate
</ResponseField>

<ResponseExample>
  ```json 200 - Success theme={null}
  {
    "wei": "6219123007416",
    "eth": "0.000006219123007416",
    "usdc": "0.01644666445335518319452825472"
  }
  ```

  ```json 401 - Authentication Error theme={null}
  {
    "message": "Not authenticated"
  }
  ```

  ```json 403 - Authorization Error theme={null}
  {
    "message": "Not authorized"
  }
  ```

  ```json 500 - Internal Server Error theme={null}
  {
    "message": "Internal server error"
  }
  ```
</ResponseExample>

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://dev.api.baanx.com/v1/wallet/credit/withdraw-estimation" \
    -H "x-client-key: YOUR_CLIENT_KEY" \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
  ```

  ```python Python theme={null}
  import requests
  from decimal import Decimal

  url = "https://dev.api.baanx.com/v1/wallet/credit/withdraw-estimation"
  headers = {
      "x-client-key": "YOUR_CLIENT_KEY",
      "Authorization": "Bearer YOUR_ACCESS_TOKEN"
  }

  response = requests.get(url, headers=headers)
  fees = response.json()

  withdrawal_amount = Decimal("100.00")
  fee_usdc = Decimal(fees['usdc'])
  net_amount = withdrawal_amount - fee_usdc

  print(f"Withdrawal Amount: {withdrawal_amount} USDC")
  print(f"Network Fee: {fee_usdc} USDC")
  print(f"You will receive: {net_amount} USDC")
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://dev.api.baanx.com/v1/wallet/credit/withdraw-estimation',
    {
      method: 'GET',
      headers: {
        'x-client-key': 'YOUR_CLIENT_KEY',
        'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
      }
    }
  );

  const fees = await response.json();

  const withdrawalAmount = 100.00;
  const feeUSDC = parseFloat(fees.usdc);
  const netAmount = withdrawalAmount - feeUSDC;

  console.log(`Fee: $${feeUSDC.toFixed(4)} USDC`);
  console.log(`Net amount: $${netAmount.toFixed(2)} USDC`);
  ```

  ```typescript TypeScript theme={null}
  interface WithdrawalFeeEstimate {
    wei: string;
    eth: string;
    usdc: string;
  }

  async function estimateWithdrawalFees(): Promise<WithdrawalFeeEstimate> {
    const response = await fetch(
      'https://dev.api.baanx.com/v1/wallet/credit/withdraw-estimation',
      {
        method: 'GET',
        headers: {
          'x-client-key': 'YOUR_CLIENT_KEY',
          'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
        }
      }
    );

    return await response.json();
  }

  const fees = await estimateWithdrawalFees();
  const withdrawalAmount = BigInt('100000000');
  const feeWei = BigInt(fees.wei);
  const netAmount = withdrawalAmount - feeWei;
  ```
</CodeGroup>

## Best Practices

<Note>
  **Fee Calculation**: Fees are estimates based on current network conditions. Actual fees may vary slightly when the transaction is executed. Always add a small buffer for production implementations.
</Note>

<Tip>
  **User Experience**: Display both the fee amount and the net amount the user will receive. This transparency helps users make informed decisions about timing their withdrawals.
</Tip>

<Warning>
  **Fee Volatility**: Gas fees on blockchains fluctuate based on network congestion. During high-traffic periods, fees can increase significantly. Consider implementing fee alerts or maximum fee thresholds.
</Warning>

## Edge Cases

### High Network Congestion

During peak network usage, gas fees can spike:

* Fees may temporarily exceed the withdrawal amount for small transactions
* Consider implementing minimum withdrawal amounts to ensure economical transactions
* Poll this endpoint periodically to catch fee reductions

### Fee Precision

Fee amounts include many decimal places for accuracy:

* Always use decimal or BigInt types, never floating-point arithmetic
* Round displayed values appropriately for user presentation
* Store full precision values for accounting purposes

### Network Limitations

Currently Linea network only:

* Other networks will return an error
* Check user's registered external wallet network before calling
* Future updates may support additional networks

## Calculation Example

```javascript Example: Net Amount Calculation theme={null}
// User wants to withdraw 100 USDC
const withdrawalAmount = 100.00;

// Fetch current fee estimate
const fees = await fetchFeeEstimate();
const feeUSDC = parseFloat(fees.usdc); // e.g., 0.01644666

// Calculate what user receives
const netAmount = withdrawalAmount - feeUSDC; // 99.98355334 USDC

// Display to user
console.log(`Withdrawal: ${withdrawalAmount} USDC`);
console.log(`Network Fee: ${feeUSDC.toFixed(6)} USDC`);
console.log(`You receive: ${netAmount.toFixed(2)} USDC`);
```

## Related Endpoints

* [Withdraw from Credit Wallet](/api-reference/wallet/credit-withdraw) - Execute withdrawal after estimating fees
* [Get Credit Wallet Balance](/api-reference/wallet/credit) - Check available balance before withdrawal
* [Get External Wallets](/api-reference/wallet/external) - View registered external wallets for withdrawal destination
