> ## 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, getVaultsByConfig, YieldType } from '@paxoslabs/amplify-sdk'

const [vault] = await getVaultsByConfig({ yieldType: YieldType.CORE, chainId: 1 })

const fee = await getWithdrawalFee({
  vaultName: vault.name,
  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                             |
| -------------- | --------- | -------- | --------------------------------------- |
| `vaultName`    | `string`  | Yes      | Account name from `getVaultsByConfig()` |
| `chainId`      | `ChainId` | Yes      | Blockchain network ID                   |
| `assetAddress` | `Address` | Yes      | Asset address for account lookup        |
| `amount`       | `string`  | Yes      | Withdrawal amount as decimal string     |
| `offerAsset`   | `Address` | Yes      | Account share token address             |
| `wantAsset`    | `Address` | Yes      | Token the user wants to receive         |
| `receiver`     | `Address` | Yes      | Address receiving the withdrawal        |

```ts theme={null}
interface GetWithdrawalFeeParams {
  vaultName: string
  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, getVaultsByConfig, YieldType } from '@paxoslabs/amplify-sdk'
import { formatUnits } from 'viem'

const [vault] = await getVaultsByConfig({ yieldType: YieldType.CORE, chainId: 1 })

const fee = await getWithdrawalFee({
  vaultName: vault.name,
  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 account matches parameters | Verify yieldType, asset, chainId |
| `"SDK not initialized"` | SDK not initialized           | Call `initAmplifySDK()` first    |

## Related

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