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

# WithdrawAuthMethod

> Withdrawal authorization method discriminated unions and type guards

The withdrawal authorization system uses discriminated unions to represent the two possible authorization methods. Type guards are provided for TypeScript narrowing.

## Import

```ts theme={null}
import {
  WithdrawAuthMethod,
  isWithdrawApprovalAuth,
  isWithdrawAlreadyApprovedAuth,
  type WithdrawAuthorizationResult,
  type WithdrawApprovalAuthorizationResult,
  type WithdrawAlreadyApprovedAuthorizationResult,
} from '@paxoslabs/amplify-sdk'
```

## WithdrawAuthMethod Enum

```ts theme={null}
export const WithdrawAuthMethod = {
  APPROVAL: 'approval',
  ALREADY_APPROVED: 'already_approved',
} as const

export type WithdrawAuthMethod =
  (typeof WithdrawAuthMethod)[keyof typeof WithdrawAuthMethod]
```

> [!NOTE]
>
> Unlike deposits, withdrawals do not support EIP-2612 permit signatures. Account
> share approvals always require an on-chain transaction.

## Result Types

### WithdrawAuthorizationResult (Discriminated Union)

```ts theme={null}
export type WithdrawAuthorizationResult =
  | WithdrawApprovalAuthorizationResult
  | WithdrawAlreadyApprovedAuthorizationResult
```

### WithdrawApprovalAuthorizationResult

Returned when an account share approval transaction is needed before submitting the withdrawal order.

```ts theme={null}
interface WithdrawApprovalAuthorizationResult {
  method: 'approval'
  /** Transaction data for vault share approve() call */
  txData: {
    abi: readonly unknown[]
    address: `0x${string}`
    functionName: 'approve'
    args: [`0x${string}`, bigint]
  }
}
```

### WithdrawAlreadyApprovedAuthorizationResult

Returned when the existing account share allowance is sufficient.

```ts theme={null}
interface WithdrawAlreadyApprovedAuthorizationResult {
  method: 'already_approved'
  /** Current allowance (human-readable) */
  allowance: string
  /** Current allowance as BigInt string */
  allowanceAsBigInt: string
}
```

## Type Guards

Use type guards for TypeScript narrowing:

```ts theme={null}
import {
  prepareWithdrawalAuthorization,
  isWithdrawApprovalAuth,
  isWithdrawAlreadyApprovedAuth,
} from '@paxoslabs/amplify-sdk'

const auth = await prepareWithdrawalAuthorization(params)

if (isWithdrawApprovalAuth(auth)) {
  // TypeScript knows: auth.method === "approval"
  // auth.txData is available with abi, address, functionName, args
  const approvalHash = await walletClient.writeContract(auth.txData)
  await publicClient.waitForTransactionReceipt({ hash: approvalHash })
}

if (isWithdrawAlreadyApprovedAuth(auth)) {
  // TypeScript knows: auth.method === "already_approved"
  // auth.allowance is available
  console.log(`Existing allowance: ${auth.allowance}`)
}
```

## Using Switch Statements

```ts theme={null}
const auth = await prepareWithdrawalAuthorization(params)

switch (auth.method) {
  case 'approval':
    // auth is narrowed to WithdrawApprovalAuthorizationResult
    await writeContract(auth.txData)
    break

  case 'already_approved':
    // auth is narrowed to WithdrawAlreadyApprovedAuthorizationResult
    console.log(`Allowance: ${auth.allowance}`)
    break
}
```

## PrepareWithdrawalAuthorizationParams

```ts theme={null}
interface PrepareWithdrawalAuthorizationParams {
  vaultName: string
  wantAsset: Address
  withdrawAmount: string
  userAddress: Address
  chainId: ChainId
  forceMethod?: 'approval' | 'allowance_check'
}
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| `vaultName` | `string` | Yes | Account name from `getVaultsByConfig()` |
| `wantAsset` | `Address` | Yes | Token the user wants to receive |
| `withdrawAmount` | `string` | Yes | Amount as decimal string |
| `userAddress` | `Address` | Yes | User's wallet address |
| `chainId` | `ChainId` | Yes | Blockchain network ID |
| `forceMethod` | `string` | No | Force `"approval"` or `"allowance_check"` (skip auto-detect) |

## Related

* [Withdrawals Guide](https://developers.paxoslabs.com/v0.5.3/intro/products/earn/developers/guides/withdrawals.md) - Using authorization in withdrawals
* [DepositAuthMethod](https://developers.paxoslabs.com/v0.5.3/intro/products/earn/developers/types/DepositAuthMethod.md) - Deposit authorization (includes permit)
* [Smart Wallets Guide](https://developers.paxoslabs.com/v0.5.3/intro/products/earn/developers/guides/smart-wallets.md) - Smart wallet routing behavior


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.