AgnicPay

Token Trading

Swap tokens on Base using DEX aggregation via AgnicPay

Token Trading

AgnicPay lets you swap tokens directly on Base through the API. Trades are executed via 0x Protocol DEX aggregation for best pricing across multiple liquidity sources.


How It Works

sequenceDiagram
    participant Client
    participant AgnicPay
    participant 0x Protocol
    participant Base Chain
 
    Client->>AgnicPay: POST /api/trade (USDC → ETH)
    AgnicPay->>0x Protocol: Get best quote
    0x Protocol-->>AgnicPay: Quote + swap calldata
    AgnicPay->>Base Chain: Approve token (if needed)
    AgnicPay->>Base Chain: Execute swap tx
    Base Chain-->>AgnicPay: Tx receipt
    AgnicPay-->>Client: Trade result + tx hash

Supported Tokens

TokenAddressDecimals
USDC0x833589fCD6eDb6E08f4c7C32D4f71b54bdA029136
ETHNative18
WETH0x420000000000000000000000000000000000000618
cbETH0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc2218
DAI0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb18
AERO0x940181a94A35A4569E4529A3CDfB74e38FD9863118

You can also pass raw contract addresses instead of symbols.

Trading is currently available on Base mainnet only. All trades are executed on-chain through 0x Protocol aggregation.


Execute a Trade

POST /api/trade

Request Body

ParameterTypeRequiredDescription
sellTokenstringYesToken to sell (symbol or address)
buyTokenstringYesToken to buy (symbol or address)
sellAmountnumberYesAmount to sell (human-readable units)
slippagePercentagenumberNoMax slippage % (default: 1.0)
networkstringNoNetwork (default: "base")

Example

curl -X POST https://api.agnic.ai/api/trade \
  -H "X-Agnic-Token: agnic_tok_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "sellToken": "USDC",
    "buyToken": "ETH",
    "sellAmount": 10,
    "slippagePercentage": 1.0
  }'

Response

{
  "success": true,
  "transactionHash": "0xabc123...",
  "sellToken": "USDC",
  "sellAmount": 10,
  "buyToken": "ETH",
  "buyAmount": "0.00396",
  "price": "2525.25",
  "slippage": "1%",
  "network": "base",
  "explorerUrl": "https://basescan.org/tx/0xabc123..."
}

Get a Quote (Dry Run)

Preview a trade without executing it.

GET /api/trade/quote

Query Parameters

ParameterTypeRequiredDescription
sellTokenstringYesToken to sell
buyTokenstringYesToken to buy
sellAmountnumberYesAmount to sell

Example

curl "https://api.agnic.ai/api/trade/quote?sellToken=USDC&buyToken=ETH&sellAmount=10" \
  -H "X-Agnic-Token: agnic_tok_YOUR_TOKEN"

Response

{
  "sellToken": "USDC",
  "buyToken": "ETH",
  "sellAmount": 10,
  "buyAmount": "0.00396",
  "price": "2525.25",
  "slippage": "1%",
  "gas": "0.0001",
  "network": "base"
}

List Supported Tokens

GET /api/trade/tokens

No authentication required. Returns all tokens available for trading.

curl https://api.agnic.ai/api/trade/tokens

Spending Limits

Trades are subject to the same spending limits as other transactions:

  • Per-transaction limit: Based on the sell amount in USD
  • Daily limit: Rolling 24-hour total
  • Monthly limit: Rolling 30-day total

Trades use the sell-side USD value for limit calculations.


Using the CLI

# Preview a trade
agnic trade 10 usdc eth --dry-run
 
# Execute a trade
agnic trade 10 usdc eth
 
# With custom slippage
agnic trade 10 usdc eth --slippage 0.5

Using the MCP Server

The trade_tokens MCP tool is available when connected to the AgnicPay MCP server:

{
  "tool": "trade_tokens",
  "parameters": {
    "sellToken": "USDC",
    "buyToken": "ETH",
    "sellAmount": 10
  }
}

Next Steps

On this page