Integration with 1inch API
Writing your own routing through DEXes yourself — it takes weeks: you need to aggregate liquidity from Uniswap v2/v3, Curve, Balancer, SushiSwap, find optimal path through graph algorithm, account for gas cost of each hop. 1inch solves this via Aggregation Protocol, which splits swaps between multiple liquidity sources. Integration takes days, not weeks — if done right.
Where Integration Usually Breaks
Stale Quote and Slippage on Execution
GET /v6.0/1/quote returns toAmount — expected output tokens. Between getting the quote and executing the transaction, time passes. On volatile markets in 10-30 seconds price can move 0.5-2%.
If you pass slippage=1 (1%) to POST /v6.0/1/swap, with actual market movement of 1.5% the transaction reverts — user paid gas and got nothing. Right approach: dynamically set slippage based on pair volatility, 0.5% for stable pairs, 1-3% for volatile ones.
Another problem: toAmount from /quote doesn't match toAmount from /swap. This is normal — /swap builds final calldata accounting for current pool state. Show user the /quote figure, sign the transaction with /swap — correct practice.
Approve and Permit: Two Patterns
1inch Aggregation Router v6 accepts tokens via standard ERC-20.approve. But for better UX it also supports permit (EIP-2612) — gasless approve via signature. If token implements EIP-2612 (DAI, USDC on Ethereum, most modern ERC-20s), use /approve/transaction endpoint only as fallback.
Check permit support: call token.nonces(address) — if not reverting, permit is supported.
Second type of approve — 1inch Permit2 (like Uniswap Permit2). If user already approved Permit2 for another protocol, repeated approve isn't needed. Improves UX with frequent swaps.
How We Integrate 1inch
Request Structure
Basic flow for swap widget:
-
GET /v6.0/{chainId}/tokens— cache list of supported tokens (once per hour enough) -
GET /v6.0/{chainId}/quote?src=...&dst=...&amount=...— get quote, show user -
GET /v6.0/{chainId}/approve/allowance?tokenAddress=...&walletAddress=...— check current allowance - If allowance < amount:
GET /v6.0/{chainId}/approve/transaction→ sign approve -
POST /v6.0/{chainId}/swap→ get calldata, send transaction
For multi-chain support use chainId in URL. 1inch supports Ethereum (1), Polygon (137), Arbitrum (42161), Optimism (10), BSC (56), Avalanche (43114), Base (8453).
API Error Handling
1inch v6 returns HTTP 400 with JSON body for any business logic error. Typical codes:
-
"Cannot estimate"— insufficient liquidity for requested amount -
"Insufficient liquidity"— same, explicit -
"fromTokenAddress cannot be equal to toTokenAddress"— UI bug - Code 429 — rate limit. Free tier: 1 RPS, Growth: 10 RPS, Enterprise: unlimited
Rate limiting should be handled via exponential backoff, don't retry immediately.
Fusion Mode vs Classic
1inch Fusion (v5+) — orderbook-based execution via resolvers. User signs order off-chain (gasless), resolver executes and pays gas. User pays through slippage. Better UX, requires @1inch/fusion-sdk integration, not REST API.
For simple integration (swap widget, dApp aggregator) — Classic mode via REST API. For advanced UX with gasless transactions — Fusion.
Verify Calldata
Before user sends transaction — always simulate via eth_call. This catches reverts before gas waste. In wagmi/viem:
const { data } = await publicClient.call({
account: userAddress,
to: swapData.tx.to,
data: swapData.tx.data,
value: BigInt(swapData.tx.value),
});
If call reverts — show user error, not transaction.
Integration Stack
viem + wagmi for TypeScript/React apps — native TypeScript support, tree-shaking, good WalletConnect and MetaMask integration. Alternative — ethers.js v6 for Node.js backend.
For caching quote data — React Query with staleTime: 10_000 (10 seconds). Older quotes not shown, request fresh.
Work Process
Requirements analysis (0.5 day). Which chains, which tokens, Classic or Fusion, own UI or embed widget.
Development (2-3 days). API layer with types, React hooks for quote/swap flow, allowance handling, error handling.
Testing (0.5-1 day). Testnet tests (1inch supports Sepolia). Check edge cases: no liquidity, insufficient balance, expired quote.
Timeline Guidelines
Basic swap functionality integration into existing dApp: 2-3 days. Full swap widget with multi-chain support, transaction history, and Fusion mode: 1-1.5 weeks.







