← Protocols
Uniswap
01Description

Largest EVM DEX. v4 introduces hooks (custom logic per pool) and singleton PoolManager; the Universal Router executes swaps across v2/v3/v4 and mixed routes in one call.

02Best for
  • 01EVM token swaps
  • 02deep on-chain liquidity
  • 03v4 hook-powered custom pools
  • 04multi-version routing via Universal Router
  • 05in-app trading widgets
03Install
  • pnpm add @uniswap/sdk-core @uniswap/v4-sdk @uniswap/universal-router-sdk @uniswap/router-sdk
04Environment variables
VariableScopeDescription
NEXT_PUBLIC_UNISWAP_API_KEYClientOptional Uniswap Trading API key for the hosted routing/quote service. Not required when calling on-chain quoter contracts directly.
05Prompt snippet
Use Uniswap for EVM swaps. For quotes, prefer the hosted Trading API (POST /v1/quote) or on-chain `Quoter`/`QuoterV2` (v3) and `V4Quoter` (v4). For execution, encode calldata with `@uniswap/universal-router-sdk` (`SwapRouter.swapCallParameters({ trade, options })`) and send to the Universal Router contract — this routes across v2, v3, v4, and mixed paths atomically with Permit2 token approvals. For v4 pools, identify a pool by its `PoolKey` (currency0, currency1, fee, tickSpacing, hooks) and pass v4-specific actions (`SWAP_EXACT_IN_SINGLE`, etc.) via `V4Planner`.
06Gotchas
  • Universal Router requires Permit2 — users must approve Permit2 on the token once, then sign a Permit2 message per swap; do not call ERC20 `approve` on the router itself.
  • v4 pools are identified by `PoolKey`, not a pool address — the singleton PoolManager holds all liquidity and hooks can revert/alter swaps, so always simulate before sending.
  • Slippage protection: pass `amountOutMinimum` (or `amountInMaximum` for exact-out) per leg; v2.1+ Universal Router enforces granular per-hop slippage on multi-hop routes.
  • Hook pools can charge dynamic fees, gate access, or add latency — assume any v4 pool with a non-zero `hooks` address may behave non-standardly and audit the hook before integrating.
  • ETH vs WETH: Universal Router accepts native ETH via `value` and unwraps/wraps automatically with `WRAP_ETH`/`UNWRAP_WETH` commands — passing WETH addresses without these commands silently breaks ETH-in/ETH-out flows.
  • Chain coverage varies by version — v4 is rolling out across L2s; check `@uniswap/v4-sdk` chain support before assuming a pool exists.
07Alternatives