Skip to content

Swap Integration

Integrate Uniswap swaps into frontends, backends, and smart contracts using the Trading API, Universal Router SDK, or direct contract calls.

Invocation

text
/swap-integration

Or describe your requirements naturally:

text
Help me add Uniswap swap functionality to my Next.js app

What It Does

This skill helps you:

  • Choose the right integration method: Trading API, Universal Router SDK, or direct smart contract calls
  • Build swap flows: Frontend React hooks, backend Node.js scripts, and Solidity integrations
  • Handle Permit2: Signature-based approvals, legacy approvals, and the rules for including permit data
  • Avoid common pitfalls: Null field handling, swap request body format, pre-broadcast validation, and L2 WETH handling

Quick Decision Guide

Building...Use This Method
Frontend with React/Next.jsTrading API
Backend script or botTrading API
Smart contract integrationUniversal Router direct calls
Need full control over routingUniversal Router SDK

Integration Methods

REST API with a 3-step flow: check_approval -> quote -> swap. Handles routing optimization automatically across all Uniswap protocol versions.

Universal Router SDK

Direct SDK usage with @uniswap/universal-router-sdk for full control over transaction construction, including manual command building with RoutePlanner.

Smart Contract Integration

On-chain Solidity contracts calling the Universal Router's execute() function with encoded commands for DeFi composability.

Routing Types

TypeDescriptionChains
CLASSICStandard AMM swap through Uniswap poolsAll supported chains
DUTCH_V2UniswapX Dutch auction V2Ethereum, Arbitrum, Base, Unichain
PRIORITYMEV-protected priority orderBase, Unichain
WRAPETH to WETH conversionAll
UNWRAPWETH to ETH conversionAll

Additional types include DUTCH_V3, DUTCH_LIMIT, LIMIT_ORDER, BRIDGE, and QUICKROUTE.

Key Topics Covered

  • Trading API reference with request/response examples
  • Universal Router command encoding and SDK patterns
  • Permit2 integration (SignatureTransfer and AllowanceTransfer modes)
  • UniswapX auction types by chain (Exclusive Dutch, Open Dutch, Priority Gas)
  • ERC-4337 smart account integration
  • Rate limiting and retry strategies
  • Contract addresses for all supported chains

Released under the MIT License.