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

# getWithdrawalFee

> Calculate withdrawal fees from the on-chain FeeModule contract

Reads the withdrawal fee from the on-chain FeeModule contract. Performs two sequential RPC calls: reads the FeeModule address from the WithdrawQueue, then multicalls `calculateOfferFees` and `offerFeePercentage`.

## Import

```ts theme={null}
import { getWithdrawalFee } from "@paxoslabs/amplify-sdk";
```

## Usage

```ts theme={null}
import { getWithdrawalFee, YieldType } from "@paxoslabs/amplify-sdk";

const fee = await getWithdrawalFee({
  yieldType: YieldType.CORE,
  chainId: 1,
  assetAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  amount: "1.0",
  offerAsset: "0x1234...5678",   // vault shares
  wantAsset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  receiver: "0x5678...abcd",
});

console.log(fee.feeAmount);     // bigint
console.log(fee.feePercentage); // bigint
```

## Parameters

| Parameter      | Type        | Required | Description                         |
| -------------- | ----------- | -------- | ----------------------------------- |
| `yieldType`    | `YieldType` | Yes      | Yield strategy type                 |
| `chainId`      | `ChainId`   | Yes      | Blockchain network ID               |
| `assetAddress` | `Address`   | Yes      | Asset address for vault lookup      |
| `amount`       | `string`    | Yes      | Withdrawal amount as decimal string |
| `offerAsset`   | `Address`   | Yes      | Vault share token address           |
| `wantAsset`    | `Address`   | Yes      | Token the user wants to receive     |
| `receiver`     | `Address`   | Yes      | Address receiving the withdrawal    |

```ts theme={null}
interface GetWithdrawalFeeParams {
  yieldType: YieldType;
  chainId: ChainId;
  assetAddress: Address;
  amount: string;
  offerAsset: Address;
  wantAsset: Address;
  receiver: Address;
}
```

## Return Type

```ts theme={null}
interface WithdrawalFeeResult {
  /** Fee amount in share token units */
  feeAmount: bigint;
  /** Fee percentage from the FeeModule */
  feePercentage: bigint;
}
```

## Example: Fee Preview

```tsx theme={null}
import { getWithdrawalFee, YieldType } from "@paxoslabs/amplify-sdk";
import { formatUnits } from "viem";

const fee = await getWithdrawalFee({
  yieldType: YieldType.CORE,
  chainId: 1,
  assetAddress: usdcAddress,
  amount: withdrawAmount,
  offerAsset: vaultShareAddress,
  wantAsset: usdcAddress,
  receiver: userAddress,
});

const feeFormatted = formatUnits(fee.feeAmount, 18);
console.log(`Withdrawal fee: ${feeFormatted} shares`);
```

## Error Handling

| Error Message Pattern   | Description                 | Resolution                       |
| ----------------------- | --------------------------- | -------------------------------- |
| `"No vault found"`      | No vault matches parameters | Verify yieldType, asset, chainId |
| `"SDK not initialized"` | SDK not initialized         | Call `initAmplifySDK()` first    |

## Related

* [Withdrawals Guide](/v0.4.2/intro/products/earn/developers/guides/withdrawals) - Complete withdrawal flow
* [getMinimumWithdrawalOrderSize](./getMinimumWithdrawalOrderSize) - Minimum order size
