Token Swaps

Swap tokens on-chain via Uniswap V3 on Base. Supports USDC, ETH, ADAO, and WETH with automatic best-price routing across fee tiers.

Overview

The Swap API enables workspace wallets to exchange one token for another directly on Uniswap V3. It handles quoting, approval, and execution in a single API call. Smart wallets batch approve + swap into one gasless user operation.

Supported Tokens

USDCETHADAOWETH

Get Swap Quote

Returns the best available price across Uniswap V3 fee tiers (0.01%, 0.05%, 0.3%, 1%).

GET /api/v1/swap/quote
  ?tokenIn=USDC
  &tokenOut=ETH
  &amount=100
  &slippageBps=50

Authorization: Bearer pd_live_...

Query Parameters

ParameterTypeRequiredDescription
tokenInstringYesToken to sell (USDC, ETH, ADAO, WETH)
tokenOutstringYesToken to buy
amountstringYesAmount of tokenIn to swap
slippageBpsnumberNoSlippage tolerance in basis points (default: 50 = 0.5%)

Response

{
  "quote": {
    "tokenIn": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "tokenOut": "0x4200000000000000000000000000000000000006",
    "tokenInSymbol": "USDC",
    "tokenOutSymbol": "ETH",
    "amountIn": "100",
    "amountOut": "0.028571",
    "amountOutMinimum": "0.028428",
    "exchangeRate": "0.00028571",
    "feeTier": 500,
    "slippageBps": 50,
    "estimatedGas": "150000",
    "route": "USDC → [0.05%] → ETH"
  },
  "timestamp": "2026-02-16T..."
}

Execute Swap

Executes the swap on-chain. For smart wallets, approve + swap is batched into a single gasless user operation via the paymaster.

POST /api/v1/swap
Authorization: Bearer pd_live_...
Content-Type: application/json

{
  "tokenIn": "USDC",
  "tokenOut": "ETH",
  "amount": "100",
  "slippageBps": 50,
  "walletType": "smart_wallet",
  "description": "Swap USDC for ETH"
}

Request Body

FieldTypeRequiredDescription
tokenInstringYesToken to sell
tokenOutstringYesToken to buy
amountstringYesAmount of tokenIn to swap
slippageBpsnumberNoSlippage tolerance (default: 50)
walletTypestringNoeoa or smart_wallet
recipientstringNoSend output tokens to a different address
descriptionstringNoHuman-readable description
metadataobjectNoArbitrary metadata

Response

{
  "swap": {
    "txHash": "0xabc123...",
    "tokenInSymbol": "USDC",
    "tokenOutSymbol": "ETH",
    "amountIn": "100",
    "expectedAmountOut": "0.028571",
    "feeTier": 500,
    "paydirectFeeBps": 50,
    "paydirectFeeAmount": "0.50",
    "walletType": "smart_wallet",
    "gasSponsored": true,
    "environment": "live",
    "status": "completed"
  },
  "timestamp": "2026-02-16T..."
}

SDK Usage

import PayDirectClient from "@paydirect/sdk";

const client = new PayDirectClient({
  apiKey: "pd_live_...",
  baseUrl: "https://www.paydirect.com/api/v1",
});

// Get a quote
const { quote } = await client.getSwapQuote({
  tokenIn: "USDC",
  tokenOut: "ETH",
  amount: "100",
});
console.log(`Rate: ${quote.exchangeRate}`);

// Execute swap
const { swap } = await client.executeSwap({
  tokenIn: "USDC",
  tokenOut: "ETH",
  amount: "100",
  walletType: "smart_wallet",
});
console.log(`Tx: ${swap.txHash}`);

Webhooks

Swap events are delivered via webhooks:

  • swap.completed — Swap executed successfully
  • swap.failed — Swap failed (with error details)

PayDirect Spread

All DEX swaps incur a 0.5% PayDirect spread on all tiers. This is applied on top of Uniswap V3 pool fees. The swap response includes paydirectFeeBps (50) and paydirectFeeAmount so you can see exactly how much goes to PayDirect.

Notes

  • Swaps route through Uniswap V3 on Base mainnet
  • The API automatically finds the best fee tier (0.01%, 0.05%, 0.3%, 1%)
  • Smart wallet swaps are gasless when the CDP Paymaster is configured
  • EOA wallets need ETH for gas (approve + swap = 2 transactions)
  • Smart wallets batch approve + swap into 1 user operation
  • A pool must exist on Uniswap V3 for the token pair — returns 404 if no liquidity