AgentSkillsCN

uniswap

通过Uniswap交易API获取兑换报价、检查批准、执行兑换并生成深度链接。

SKILL.md
--- frontmatter
name: uniswap
version: 1.0.0
description: Get swap quotes, check approvals, execute swaps, and generate deep links using the Uniswap Trading API.
author: aimaneth
license: MIT
tags:
  - crypto
  - defi
  - trading
  - uniswap
env_needed:
  - name: UNISWAP_API_KEY
    description: API key from the Uniswap Developer Portal (https://developers.uniswap.org/)
    required: true
metadata: {"zeptoclaw":{"emoji":"🦄","requires":{"anyBins":["curl","jq"]}}}

Uniswap Skill

Interact with Uniswap — the largest decentralised exchange — via the Trading API. Get swap quotes, check token approvals, execute swaps, and generate deep links that open the Uniswap UI with pre-filled parameters.

Based on Uniswap AI — adapted for ZeptoClaw agents.

Setup

  1. Get an API key from the Uniswap Developer Portal
  2. Set environment variable:
bash
export UNISWAP_API_KEY="your_api_key_here"

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

Required headers for all requests:

code
Content-Type: application/json
x-api-key: $UNISWAP_API_KEY
x-universal-router-version: 2.0

Get a Swap Quote

Get the best price for a token swap. This is the most common operation.

bash
curl -s -X POST https://trade-api.gateway.uniswap.org/v1/quote \
  -H "Content-Type: application/json" \
  -H "x-api-key: $UNISWAP_API_KEY" \
  -H "x-universal-router-version: 2.0" \
  -d '{
    "swapper": "0xYOUR_WALLET_ADDRESS",
    "tokenIn": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
    "tokenOut": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "tokenInChainId": "1",
    "tokenOutChainId": "1",
    "amount": "1000000000000000000",
    "type": "EXACT_INPUT",
    "slippageTolerance": 0.5,
    "routingPreference": "BEST_PRICE"
  }' | jq .

The above example quotes swapping 1 WETH → USDC on Ethereum mainnet.

Key parameters:

ParameterValues
typeEXACT_INPUT or EXACT_OUTPUT
slippageTolerance0–100 (percentage)
routingPreferenceBEST_PRICE, FASTEST, or CLASSIC
protocolsOptional: ["V2", "V3", "V4"]

Response includes quote.output.amount, quote.gasFeeUSD, and routing details.

Tip: Use the gasFeeUSD field to display gas costs. Don't manually convert gasFee (wei) — it leads to inaccurate estimates.

Check Token Approval

Before swapping ERC-20 tokens, check if the token is approved for the Uniswap router.

bash
curl -s -X POST https://trade-api.gateway.uniswap.org/v1/check_approval \
  -H "Content-Type: application/json" \
  -H "x-api-key: $UNISWAP_API_KEY" \
  -H "x-universal-router-version: 2.0" \
  -d '{
    "walletAddress": "0xYOUR_WALLET_ADDRESS",
    "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "amount": "1000000000",
    "chainId": 1
  }' | jq .
  • If approval is null — token is already approved, proceed to swap.
  • If approval contains a transaction — sign and submit it before swapping.

Execute a Swap (3-Step Flow)

The full swap flow is: check_approval → quote → swap.

After getting a quote, send it to the swap endpoint to get a ready-to-sign transaction:

bash
# Step 1: Get quote (see above)
# Step 2: Send quote response to /swap
curl -s -X POST https://trade-api.gateway.uniswap.org/v1/swap \
  -H "Content-Type: application/json" \
  -H "x-api-key: $UNISWAP_API_KEY" \
  -H "x-universal-router-version: 2.0" \
  -d '{
    "routing": "CLASSIC",
    "quote": {
      "input": {"token": "0x...", "amount": "1000000000000000000"},
      "output": {"token": "0x...", "amount": "999000000"},
      "slippage": 0.5
    },
    "swapper": "0xYOUR_WALLET_ADDRESS",
    "tokenIn": "0x...",
    "tokenOut": "0x...",
    "tokenInChainId": "1",
    "tokenOutChainId": "1",
    "amount": "1000000000000000000",
    "type": "EXACT_INPUT"
  }' | jq .

Response returns a ready-to-sign transaction with to, from, data, value, and gasLimit.

Important: Spread the quote response into the swap request body — don't wrap it in {"quote": ...}. Also strip any null fields like permitData: null before sending.

Generate a Uniswap Deep Link

Generate a URL that opens the Uniswap swap interface with parameters pre-filled:

bash
# ETH → USDC on Ethereum
echo "https://app.uniswap.org/swap?chain=ethereum&inputCurrency=ETH&outputCurrency=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&exactAmount=1&exactField=input"

# USDC → ETH on Base
echo "https://app.uniswap.org/swap?chain=base&inputCurrency=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&outputCurrency=ETH&exactAmount=100&exactField=input"

Deep link parameters:

ParameterDescription
chainethereum, base, arbitrum, etc.
inputCurrencyToken address or ETH
outputCurrencyToken address or ETH
exactAmountAmount in human-readable units
exactFieldinput or output

Supported Chains

Chain IDChainChain IDChain
1Ethereum8453Base
10Optimism42161Arbitrum
56BNB Chain42220Celo
130Unichain43114Avalanche
137Polygon81457Blast
196X Layer7777777Zora
324zkSync480World Chain

Common Token Addresses

TokenEthereum (1)Base (8453)
WETH0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc20x4200000000000000000000000000000000000006
USDC0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB480x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
USDT0xdAC17F958D2ee523a2206206994597C13D831ec7
DAI0x6B175474E89094C44Da98b954EedeAC495271d0F

Tips

  • Quote freshness: Quotes expire quickly — get a fresh quote right before executing a swap
  • Slippage: Use 0.5 (0.5%) for stablecoins, 1.03.0 for volatile pairs
  • Chain IDs as strings: tokenInChainId and tokenOutChainId must be strings (e.g. "1"), not numbers
  • Permit2: When using Permit2, signature and permitData must both be present or both absent — never set permitData: null
  • Native ETH: Use ETH in deep links. For API calls, use the WETH address
  • Amount format: Amounts are in the token's smallest unit (wei for ETH = 18 decimals, 6 decimals for USDC)
  • Rate limits: Be mindful of API rate limits — cache quotes when displaying to users