Important: Never manually call
approve() functions when using OneBalance. The platform automatically manages all required approvals as part of the contract call preparation process.How Approval Management Works
When you specifyallowanceRequirements, OneBalance automatically:
- Checks existing allowances - Verifies current approval amounts
- Adds approval transactions - Only when needed, for exact amounts
- Executes your operations - Runs your contract calls
- Removes excess approvals - Cleans up remaining allowances for security
OneBalance bundles approvals, your calls, and approval cleanup into a single user operation for atomic execution.
Basic Example
Here’s how to properly handle approvals for a DEX swap:swap-with-approval.ts
What NOT to Do
Common Mistake: Including approval calls manually will cause transaction failures.
wrong-approach.ts
Common Patterns
DEX Swaps
dex-swap.ts
Lending Protocols
aave-deposit.ts
Multiple Token Operations
multi-token-defi.ts
NFT Purchases
nft-purchase.ts
Special Cases
Native Tokens (ETH, MATIC, etc.)
Native tokens don’t require approvals - they’re sent directly:native-token.ts
Existing Allowances
OneBalance optimizes gas by checking existing allowances:Sufficient Allowance
If
current allowance ≥ required amount, no approval transaction is addedInsufficient Allowance
Only approves the exact amount needed, not unlimited approvals
Security Features
OneBalance’s approval management includes several security measures:- Exact Amount Approvals - Never approves more than needed
- Automatic Cleanup - Removes remaining allowances after execution
- Front-running Protection - Atomic bundling prevents manipulation
- Approval Validation - Verifies spender addresses match your calls
Best Practices
1
Use allowanceRequirements
Always specify token approvals in the
allowanceRequirements array, never in calls2
Specify Exact Amounts
Use precise amounts to minimize approval exposure
3
Verify Spender Addresses
Double-check that spender addresses match your contract calls
4
Test with Small Amounts
Start with small transactions to verify your integration
TypeScript Interface
interfaces.ts
Troubleshooting
- Transaction fails with ‘Approval not found’ - Make sure you’re using
allowanceRequirementsinstead of manual approval calls. - Gas costs seem high - OneBalance only adds approvals when needed. High gas might indicate multiple tokens or complex operations.
- Spender address mismatch - Verify that the spender in
allowanceRequirementsmatches the contract address in yourcalls. - Amount calculation errors - Ensure you’re using the correct decimals for the token (e.g., 6 for USDC, 18 for most ERC20s).
Need help? Check the troubleshooting guide for common issues and solutions.