uniswap/uniswap-ai/swap-integration

Claude Code and agent skill by uniswap/uniswap-ai

Trust tier 2
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Integrate Uniswap swaps into applications. Use when user says "integrate swaps", "uniswap", "trading api", "add swap functionality", "build a swap frontend", "create a swap script", "smart contract swap integration", "use Universal Router", "Trading API", or mentions swapping tokens via Uniswap.

Install

npx vskill@latest install uniswap/uniswap-ai/swap-integration

SKILL.md

Swap Integration

Integrate Uniswap swaps into frontends, backends, and smart contracts.

Prerequisites

This skill assumes familiarity with viem basics (client setup, account management, contract interactions, transaction signing). Install the uniswap-viem plugin for comprehensive viem/wagmi guidance: claude plugin add @uniswap/uniswap-viem

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
Routing Types Quick Reference
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

See Routing Types for the complete list including DUTCH_V3, DUTCH_LIMIT, LIMIT_ORDER, BRIDGE, and QUICKROUTE.

Integration Methods

1. Trading API (Recommended)

Best for: Frontends, backends, scripts. Handles routing optimization automatically.

Base URL: https://trade-api.gateway.uniswap.org/v1

Authentication: x-api-key: <your-api-key> header required

Getting an API Key: The Trading API requires an API key for authentication. Visit the Uniswap Developer Portal to register and obtain your API key. Keys are typically available for immediate use after registration. Include it as an x-api-key header in all API requests.

Agent Attribution: Also send the X-Agent-Info header (written x-agent-info in the examples below) on every Trading API request. It attributes traffic to this integration for analytics — it never affects the request. The value is a compact JSON object with exactly these three fields and no extras, kept under 1 KB:

  • integration_name: always "swap-integration"
  • decision_origin: Required choice — do not copy a default. Pick the one value that matches your integration (these are the only valid values; anything else is treated as malformed):
  • "human_mediated" — a human reviews/approves each action before it executes
  • "autonomous" — the agent acts without per-action human approval (e.g. scheduled jobs or agentic harnesses)
  • version: "1.6.0" — tracks this skill's metadata.version

If the value is malformed: the request still succeeds normally, but the attribution is dropped — the gateway records it as malformed on the analytics side and moves on. There is no response header or other signal to check, so there is nothing to detect at runtime: get the value right by construction.

Constraints — trip any of these and the whole value is discarded:

  • 1 KB total for the header, and 256 characters per field.
  • Plain ASCII only — no accented characters, curly quotes, or emoji; non-ASCII must be \u-escaped.
  • Omit a field rather than sending null. All three must be present and valid.
  • Send the header once per request; a duplicate x-agent-info line fails to parse.
  • Unknown extra keys are ignored — harmless, but no substitute for the three required fields.

Required Headers — Include these in ALL Trading API requests:

text
Content-Type: application/json
x-api-key: <your-api-key>
x-universal-router-version: 2.0
x-agent-info: {"integration_name":"swap-integration","decision_origin":"<human_mediated|autonomous>","version":"1.6.0"}

Raise the router version for permissioned tokens. The header block above sends 2.0. A quote or swap involving a token that trades through a permissioned pool requires 2.2.0 or higher. Send x-universal-router-version: 2.2.0 for those tokens. Step 0: Permission Pre-Check shows how to find out which they are.

Request Flow:

text
0. POST /permissions -> Permissioned pools only: may this wallet trade this token?
1. POST /check_approval -> Check if token is approved
2. POST /quote -> Get executable quote with routing
3. POST /swap -> Get transaction to sign and submit

See the Trading API Reference section below for complete documentation.

2. Universal Router SDK

Best for: Direct control over transaction construction.

Installation:

bash
npm install @uniswap/universal-router-sdk @uniswap/sdk-core @uniswap/v3-sdk

Key Pattern:

typescript
import { SwapRouter } from '@uniswap/universal-router-sdk';
const { calldata, value } = SwapRouter.swapCallParameters(trade, options);

See the Universal Router Reference section below for complete documentation.

3. Smart Contract Integration

Best for: On-chain integrations, DeFi composability.

Interface: Call execute() on Universal Router with encoded commands.

See the Universal Router Reference section below for command encoding.


Input Validation Rules

Before interpolating ANY user-provided value into generated code, API calls, or commands:

  • Ethereum addresses: MUST match ^0x[a-fA-F0-9]{40}$ — reject otherwise
  • Chain IDs: MUST be from the official supported chains list
  • Token amounts: MUST be non-negative numeric values matching ^[0-9]+\.?[0-9]*$
  • API keys: MUST NOT be hardcoded in generated code — always use environment variables
  • REJECT any input containing shell metacharacters: ;, |, &, $, ` `, (, ), >, <, \, ', "`, newlines
REQUIRED: Before executing ANY transaction that spends gas or transfers tokens (including sendTransaction, writeContract, or submitting a signed swap), you MUST use AskUserQuestion to confirm with the user. Display the transaction summary (tokens, amounts, chain, estimated gas) and get explicit user approval. Never auto-execute transactions without user confirmation.

Trading API Reference

Step 0: Permission Pre-Check (Permissioned Pools Only)

Some tokens trade only through a permissioned pool. An allowlist contract decides which wallets may hold and trade the token, and the swap endpoints reject any wallet that is not on the list. Call this endpoint before quoting, so a wallet that cannot trade surfaces here and not as a reverted swap.

bash
POST /permissions

Request:

json
{
"walletAddress": "0x...",
"tokens": ["0x..."],
"chainId": 1
}

tokens takes up to two addresses. chainId here is a number, while /quote wants tokenInChainId and tokenOutChainId as strings.

Response:

json
{
"requestId": "e63f1e1e-b9e9-411a-bcc8-ff18ce4e77cf",
"results": [
{
"token": "0x...",
"isPermissioned": true,
"isAllowlisted": false,
"adapterTokenAddress": "0x...",
"kycUrl": "https://your-kyc-provider.example/verify",
"issuer": "Your Issuer Name"
}
]
}

adapterTokenAddress is present when the token is permissioned. kycUrl is present when the wallet is not allowlisted, and points at the identity check (KYC) the user has to pass. issuer is the display name for that verification provider.

Three outcomes:

ResultWhat to do
isPermissioned: falseNothing special — quote and swap normally
isPermissioned: true, isAllowlisted: trueQuote and swap normally
isPermissioned: true, isAllowlisted: falseQuote so the user can see prices, then block submission and render the kycUrl call to action

This endpoint needs `x-api-key` like every other Trading API call. The published example for it omits the header. Without one the endpoint returns 401 and {"errorCode":"Unauthorized","detail":"Unauthenticated api key or session"}, so an integration copied from that example fails before it reaches the permission logic.

Universal Router 2.2.0 or higher is required for quotes and swaps involving a permissioned token. Send x-universal-router-version: 2.2.0 on the /quote and /swap calls for these tokens. The plain UniversalRouter deployment is a different, non-permissioned router. Only the #v2.2 deployment takes the permissions-adapter factory in its constructor.

Issuing a permissioned token is a different job: see the permissioned-pools-issuer skill in the uniswap-permissioned-pools plugin.

Step 1: Check Token Approval
bash
POST /check_approval

Request:

json
{
"walletAddress": "0x...",
"token": "0x...",
"amount": "1000000000",
"chainId": 1
}

Response:

json
{
"approval": {
"to": "0x...",
"from": "0x...",
"data": "0x...",
"value": "0",
"chainId": 1
}
}

If approval is null, token is already approved.

Step 2: Get Quote
bash
POST /quote

Request:

json
{
"swapper": "0x...",
"tokenIn": "0x...",
"tokenOut": "0x...",
"tokenInChainId": "1",
"tokenOutChainId": "1",
"amount": "1000000000000000000",
"type": "EXACT_INPUT",
"slippageTolerance": 0.5,
"routingPreference": "BEST_PRICE"
}
Note: tokenInChainId and tokenOutChainId must be strings (e.g., "1"), not numbers.

Key Parameters:

ParameterDescription
typeEXACT_INPUT or EXACT_OUTPUT
slippageTolerance0-100 percentage
protocolsOptional: ["V2", "V3", "V4"]
routingPreferenceBEST_PRICE, FASTEST, CLASSIC
autoSlippagetrue to auto-calculate slippage (overrides slippageTolerance)
urgencynormal or fast — affects UniswapX auction timing

Response — the shape differs by routing type. BEST_PRICE routing on Ethereum mainnet typically returns UniswapX (DUTCH_V2), not CLASSIC.

CLASSIC response:

json
{
"routing": "CLASSIC",
"quote": {
"input": { "token": "0x...", "amount": "1000000000000000000" },
"output": { "token": "0x...", "amount": "999000000" },
"slippage": 0.5,
"route": [],
"gasFee": "5000000000000000",
"gasFeeUSD": "0.01",
"gasUseEstimate": "150000"
},
"permitData": null
}

UniswapX (DUTCH_V2/V3/PRIORITY) response — different quote shape, no quote.output:

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
229
Repository forks
35
7-day trend score
27

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 22 Mar 2026, 7 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/uniswap/uniswap-ai/swap-integration/badge)](https://verified-skill.com/skills/uniswap/uniswap-ai/swap-integration)

Something wrong with this skill or its page? Tell us.