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
- Get an API key from the Uniswap Developer Portal
- Set environment variable:
export UNISWAP_API_KEY="your_api_key_here"
Base URL: https://trade-api.gateway.uniswap.org/v1
Required headers for all requests:
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.
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:
| Parameter | Values |
|---|---|
type |
EXACT_INPUT or EXACT_OUTPUT |
slippageTolerance |
0โ100 (percentage) |
routingPreference |
BEST_PRICE, FASTEST, or CLASSIC |
protocols |
Optional: ["V2", "V3", "V4"] |
Response includes quote.output.amount, quote.gasFeeUSD, and routing details.
Tip: Use the
gasFeeUSDfield to display gas costs. Don't manually convertgasFee(wei) โ it leads to inaccurate estimates.
Check Token Approval
Before swapping ERC-20 tokens, check if the token is approved for the Uniswap router.
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
approvalisnullโ token is already approved, proceed to swap. - If
approvalcontains 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:
# 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 anynullfields likepermitData: nullbefore sending.
Generate a Uniswap Deep Link
Generate a URL that opens the Uniswap swap interface with parameters pre-filled:
# 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:
| Parameter | Description |
|---|---|
chain |
ethereum, base, arbitrum, etc. |
inputCurrency |
Token address or ETH |
outputCurrency |
Token address or ETH |
exactAmount |
Amount in human-readable units |
exactField |
input or output |
Supported Chains
| Chain ID | Chain | Chain ID | Chain |
|---|---|---|---|
| 1 | Ethereum | 8453 | Base |
| 10 | Optimism | 42161 | Arbitrum |
| 56 | BNB Chain | 42220 | Celo |
| 130 | Unichain | 43114 | Avalanche |
| 137 | Polygon | 81457 | Blast |
| 196 | X Layer | 7777777 | Zora |
| 324 | zkSync | 480 | World Chain |
Common Token Addresses
| Token | Ethereum (1) | Base (8453) |
|---|---|---|
| WETH | 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 |
0x4200000000000000000000000000000000000006 |
| USDC | 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 |
0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| USDT | 0xdAC17F958D2ee523a2206206994597C13D831ec7 |
โ |
| DAI | 0x6B175474E89094C44Da98b954EedeAC495271d0F |
โ |
Tips
- Quote freshness: Quotes expire quickly โ get a fresh quote right before executing a swap
- Slippage: Use
0.5(0.5%) for stablecoins,1.0โ3.0for volatile pairs - Chain IDs as strings:
tokenInChainIdandtokenOutChainIdmust be strings (e.g."1"), not numbers - Permit2: When using Permit2,
signatureandpermitDatamust both be present or both absent โ never setpermitData: null - Native ETH: Use
ETHin 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