
Swap Integration
Wire Uniswap Trading API quotes and swap calldata into your app—or an ERC-4337 smart-account bot—for production-grade token swaps on L2s.
Overview
Swap integration is an agent skill for the Build phase that implements Uniswap Trading API swap flows—including smart-account ERC-4337 execution, L2 WETH, and rate limiting—for automated on-chain trades.
Install
npx skills add https://github.com/uniswap/uniswap-ai --skill swap-integrationWhat is this skill?
- Standard 3-step Trading API flow extended with /v1/swap calldata retrieval
- Smart account pattern: quote → execution → delegation redemption → bundler UserOperation
- ERC-4337 delegation types and viem encodeFunctionData examples on Base
- Supplementary topics: L2 WETH handling and API rate limiting
- Oriented toward automated services (DCA bots, portfolio rebalancers)
- Documents a 3-step Trading API flow through /v1/swap
- Architecture chain: Trading API calldata → execution → delegation redemption → bundler UserOperation
Adoption & trust: 1.1k installs on skills.sh; 212 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You have quotes from Uniswap’s API but no reliable path to calldata, permits, smart-account UserOperations, or L2-specific token handling.
Who is it for?
Indie builders adding swap execution to a dApp, agent trader, or rebalancer on EVM L2s with viem.
Skip if: Pure UI-only swap widgets with no custom backend or smart-account requirements, or non-EVM chains outside the documented API.
When should I use this skill?
Implementing Uniswap Trading API swaps, smart-account automation, or L2 WETH and rate-limit handling in TypeScript.
What do I get? / Deliverables
You implement a typed swap pipeline from Trading API responses through delegation-aware execution ready for bots or backend services.
- Swap calldata fetch and execution module
- Optional ERC-4337 UserOperation path for delegated swaps
Recommended Skills
Journey fit
Build/integrations is where you connect external swap APIs, viem clients, and bundlers—not a launch or growth task. Third-party Trading API + on-chain execution paths are classic integration work during product construction.
How it compares
Integration skill for Uniswap’s HTTP Trading API and on-chain calldata—not a generic DEX aggregator MCP or wallet SDK tutorial alone.
Common Questions / FAQ
Who is swap-integration for?
Developers building EVM swap features, DCA bots, or delegated smart-account services who already use viem and need Uniswap gateway patterns.
When should I use swap-integration?
During Build while wiring POST swap endpoints, cleaning permit fields from quotes, and connecting bundlers for ERC-4337 automation.
Is swap-integration safe to install?
It describes live trading and key-bearing flows—review the Security Audits panel on this Prism page and never paste production secrets into agent chats.
SKILL.md
READMESKILL.md - Swap Integration
# Advanced Trading API Patterns Supplementary patterns for the swap-integration skill covering smart account integration, L2 WETH handling, and rate limiting. ## Smart Account Integration (ERC-4337) Execute Trading API swaps through ERC-4337 smart accounts using delegation and bundlers. This pattern is useful for automated services (DCA bots, portfolio rebalancers) that execute swaps on behalf of users via delegated smart accounts. ### Architecture ```text Trading API (get calldata) -> Create Execution -> Delegation Redemption -> Bundler (UserOperation) ``` ### Full Pattern ```typescript import { createPublicClient, createWalletClient, http, type Address, type Hex, encodeFunctionData, } from 'viem'; import { base } from 'viem/chains'; // Types for smart account integration interface SwapCalldata { to: Address; data: Hex; value: string; } interface Execution { target: Address; callData: Hex; value: bigint; } interface SignedDelegation { delegator: Address; delegate: Address; authority: Hex; caveats: readonly unknown[]; salt: bigint; signature: Hex; } // 1. Get swap calldata from Trading API (standard 3-step flow) async function getSwapCalldata( quoteResponse: Record<string, unknown>, apiKey: string ): Promise<SwapCalldata> { const { permitData, permitTransaction, ...cleanQuote } = quoteResponse; const swapRes = await fetch('https://trade-api.gateway.uniswap.org/v1/swap', { method: 'POST', headers: { 'x-api-key': apiKey, 'Content-Type': 'application/json' }, body: JSON.stringify({ ...cleanQuote, ...(permitData && { permitData }), }), }); const swapData = await swapRes.json(); if (!swapRes.ok) throw new Error(swapData.detail || 'Swap request failed'); return swapData.swap; } // 2. Create execution for delegation redemption function createExecution(swap: SwapCalldata): Execution { return { target: swap.to, // Universal Router address callData: swap.data, value: BigInt(swap.value), }; } // 3. Submit via bundler as a UserOperation async function executeViaSmartAccount( bundlerClient: { sendUserOperation: (params: { account: unknown; calls: readonly { to: Address; data: Hex; value?: bigint }[]; }) => Promise<Hex>; }, delegateSmartAccount: unknown, delegationManagerAddress: Address, signedDelegation: SignedDelegation, execution: Execution ): Promise<Hex> { // Encode the delegation redemption call const redeemData = encodeFunctionData({ abi: [ { name: 'redeemDelegations', type: 'function', inputs: [ { name: 'delegations', type: 'tuple[][]', components: [] }, { name: 'modes', type: 'uint8[]' }, { name: 'executions', type: 'tuple[][]', components: [] }, ], outputs: [], }, ] as const, functionName: 'redeemDelegations', args: [ [[signedDelegation]], // delegations (array of delegation chains) [0], // modes (0 = SingleDefault) [[execution]], // executions ], }); return bundlerClient.sendUserOperation({ account: delegateSmartAccount, calls: [ { to: delegationManagerAddress, data: redeemData, value: execution.value, }, ], }); } // Complete flow async function swapViaSmartAccount( quoteResponse: Record<string, unknown>, apiKey: string, bundlerClient: Parameters<typeof executeViaSmartAccount>[0], delegateSmartAccount: Parameters<typeof executeViaSmartAccount>[1], delegationManagerAddress: Address, signedDelegation: SignedDelegation ): Promise<Hex> { // Get swap calldata from Trading API const swapCalldata = await getSwapCalldata(quoteResponse, apiKey); // Create execution for delegation const execution = createExecution(swapCalldata); // Submit via bundler return executeViaSmartAccount( bundlerClient, delegateSmartAccount, delegationManagerAddress, signedDelegation, execution );