- Checks existing account share allowance
- Detects smart contract wallets (Safe, EIP-4337, EIP-7702)
- Returns the appropriate authorization result
Import
Usage
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
vaultName | string | Yes | Account name from AmplifyVault.name (e.g. from getVaultsByConfig()) |
wantAsset | Address | Yes | Token address to receive upon withdrawal |
withdrawAmount | string | Yes | Account shares to withdraw (decimal string) |
userAddress | Address | Yes | Owner of account shares |
chainId | number | Yes | Blockchain network ID |
forceMethod | "approval" | "allowance_check" | No | Override auto routing behavior |
Return Type
Returns a discriminated unionWithdrawAuthorizationResult:
WithdrawAuthMethod.APPROVAL
Returned when approval is needed (insufficient allowance, smart wallet detected in auto mode, orforceMethod: "approval").
WithdrawAuthMethod.ALREADY_APPROVED
Returned when existing allowance is sufficient.Type Guards
Use type guards for type-safe handling:Smart Wallet Behavior
In auto mode, smart contract wallets (Safe, EIP-4337, EIP-7702) are routed toAPPROVAL with approve tx data so they can batch approve + withdraw atomically.
getCode. This covers:
- Safe (Gnosis Safe) multi-sig wallets
- EIP-4337 smart accounts (e.g., Biconomy, ZeroDev, Alchemy)
- EIP-7702 delegated EOAs
- Privy embedded wallets (when using smart wallets)
Force Method Overrides
UseforceMethod for deterministic behavior:
Examples
- Complete Viem Flow
- Smart Wallet Batching
Comparison with Deposit Authorization
prepareWithdrawalAuthorization() mirrors the deposit flow’s prepareDepositAuthorization():
| Feature | Deposit Auth | Withdrawal Auth |
|---|---|---|
| Methods | PERMIT, APPROVAL, ALREADY_APPROVED | APPROVAL, ALREADY_APPROVED |
| Permit Support | Yes (EIP-2612) | No |
| Smart Wallet Auto-Detect | Yes | Yes |
| Force Method | forceMethod: "permit" | "approval" | forceMethod: "approval" | "allowance_check" |
Error Handling
| Error | Description | Resolution |
|---|---|---|
Vault not found | Invalid account name | Verify account name via getVaultsByConfig() |
Failed to check withdrawal approval | On-chain multicall failed | Check RPC connectivity and retry |
Related
- getVaultsByConfig - Discover account names
- prepareDepositAuthorization - Deposit authorization (equivalent for deposits)
- prepareWithdrawal - Unified withdrawal wrapper
- prepareWithdrawOrderTxData - Low-level withdrawal tx builder
- prepareApproveWithdrawOrderTxData - Manual approval
- Withdrawals Guide - Complete withdrawal integration guide
- Smart Wallets Guide - Smart wallet integration patterns