prepareDepositAuthorization() to determine the method, then prepareDeposit() to execute.
Import
prepareDepositAuthorization()
Determines the optimal authorization method for a deposit operation.Function Signature
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
vaultName | string | Yes | Account name from AmplifyVault.name (e.g. from getVaultsByConfig()) |
depositAsset | Address | Yes | Token contract address to deposit |
depositAmount | string | Yes | Amount as decimal string (e.g., “100.25”) |
to | Address | Yes | Recipient address for account shares |
chainId | number | Yes | Blockchain network ID |
deadline | bigint | No | Permit deadline (defaults to 1 hour) |
forceMethod | "permit" | "approval" | No | Override automatic detection |
Return Type (Discriminated Union)
- Type Definition
- Permit Result
- Approval Result
- Already Approved Result
Decision Logic
The function follows this priority order:- Check
forceMethod— If specified, use that method directly - Detect smart wallet — If the address has deployed bytecode (Safe, EIP-4337, EIP-7702), route to
APPROVALso callers can batch approve + deposit atomically - Check permit support — If the token supports EIP-2612, return permit signature data
- Check existing allowance — If sufficient, return
ALREADY_APPROVED - Default to approval — Return approval transaction data
Token Permit Support
The following table shows which supported tokens use the gas-efficient EIP-2612 permit path versus the standard ERC-20 approval path. The SDK detects this automatically — useforceMethod: "approval" to override when needed (e.g., smart contract wallets).
| Token | Authorization Method | Notes |
|---|---|---|
| USDC | Permit (EIP-2612) | Single-transaction gasless signature |
| USDG | Permit (EIP-2612) | Single-transaction gasless signature |
| pyUSD | Permit (EIP-2612) | Single-transaction gasless signature |
| USD₮0 | Permit (EIP-2612) | Single-transaction gasless signature |
| USDT | Approval (ERC-20) | Requires separate approval transaction. Also requires resetting allowance to 0 before setting a new value when a non-zero allowance already exists. |
prepareDeposit()
Prepares transaction data for a deposit, automatically using the correct method based on provided parameters.Function Signature
Parameters
Return Type
Returns a discriminated union based on which deposit method is used:Both result variants have the same flat
txData shape — txData.abi,
txData.address, txData.functionName, txData.args, txData.chainId. You
can spread txData directly into viem’s writeContract regardless of method.Complete Flow Example
Force Specific Method
Override automatic detection when needed:Slippage Configuration
Error Handling
| Error Message Pattern | Description | Resolution |
|---|---|---|
"SDK not initialized" | SDK used before init | Call initAmplifySDK() first |
"Vault not found" | No account matches vaultName | Verify account name via getVaultsByConfig() |
"does not support EIP-2612 permit" | Token doesn’t support permits | Use approval flow instead |
"requires both signature and deadline" | Missing permit params | Provide signature and deadline for permit deposits |
Related
- getVaultsByConfig - Discover account names
- Deposits Guide - Complete integration examples
- DepositAuthMethod - Type definitions
- prepareDepositTxData - Lower-level deposit function