swap-integration

Integrate Uniswap token swaps into frontends, backends, and smart contracts via Trading API and Universal Router.

Updated Jul 7, 2025
One-click install
npx skills add https://github.com/Catalyst-Astro/Catalyst-Blockchain-Structural-Token- --skill swap-integration-catalyst-astro
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swap-integration
Source: https://github.com/Catalyst-Astro/Catalyst-Blockchain-Structural-Token-/tree/main/.agents/skills/swap-integration
Command: npx skills add https://github.com/Catalyst-Astro/Catalyst-Blockchain-Structural-Token- --skill swap-integration-catalyst-astro

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @uniswap/universal-router-sdk, @uniswap/sdk-core, @uniswap/v3-sdk, @uniswap/router-sdk, viem, buffer, and includes references (resource) components.

What problem does it solve? Adding token swap functionality to an application requires handling routing optimization, token approvals, Permit2 signatures, quote freshness, and chain-specific quirks. This Skill provides the complete integration patterns for Uniswap swaps so developers avoid common pitfalls like malformed /swap request bodies, CORS failures, and on-chain reverts. ## Core Features & Use Cases - Trading API Integration: Implements the 3-step flow (check_approval, quote, swap) with correct request formatting, Permit2 handling, and routing-type-aware response parsing for CLASSIC and UniswapX orders. - Universal Router SDK & Smart Contracts: Generates direct on-chain integration code using @uniswap/universal-router-sdk with command encoding for v2, v3, and v4 swaps. - Production Hardening: Covers browser polyfills, CORS proxy configuration for Vite/Next.js/Vercel, pre-broadcast transaction validation, rate-limit backoff, and L2 WETH unwrapping. - Use Case: A developer building a React frontend on Base asks to add a USDC-to-WETH swap widget; the Skill produces the proxied API calls, quote display logic, Permit2 signing flow, and transaction submission with user confirmation. ## Quick Start Ask the assistant to integrate a Uniswap token swap into your app, specifying the tokens, chain, and whether it is a frontend, backend script, or smart contract.

Frequently Asked Questions about swap-integration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I integrate Uniswap swaps into a React frontend?

Use the Uniswap Trading API with its 3-step flow: POST /check_approval, POST /quote, then POST /swap. Because the API does not support browser CORS preflight, proxy requests through your dev server or platform rewrites, and add the Buffer polyfill for viem.

Trading API vs Universal Router SDK: which should I use?

Use the Trading API for frontends, backends, and bots since it handles routing optimization automatically. Use the Universal Router SDK when you need direct control over transaction construction, and call the Universal Router contract directly for smart contract integrations.

Why does the Uniswap /swap endpoint return a quote validation error?

The error usually means the quote was wrapped in a quote field instead of spread into the request body, or permitData was included for a UniswapX route. Spread the quote response directly and strip permitData for DUTCH_V2, DUTCH_V3, and PRIORITY routes.

Does the Uniswap Trading API work in the browser?

Not directly, because the API rejects CORS preflight OPTIONS requests with 415 Unsupported Media Type. You must proxy requests through your own server using Vite dev proxy, Next.js rewrites, Vercel rewrites, or Cloudflare Pages redirects.

Why did my swap output WETH instead of ETH on Base?

On L2 chains like Base, Optimism, and Arbitrum, swaps outputting ETH often deliver WETH because the UNWRAP_WETH command is not always included. Check the WETH balance after the swap and call withdraw on the WETH contract to unwrap it.

How do I handle Uniswap Trading API rate limits?

The API allows roughly 10 requests per second per endpoint. Implement exponential backoff with jitter for 429 responses, add 100-200ms delays between sequential calls, and cache approval check results to reduce request volume.