DEV Community

Give your AI agent a cross-DEX spread tool it pays for itself (x402 + MCP, no account, no key)

AI agents are starting to pay for data directly. The x402 protocol lets an HTTP
endpoint answer a request with 402 Payment Required, the client signs a small
USDC payment, and the same request is retried and served. No signup, no API key
to request, no invoice — the agent just pays a cent and gets the data.

I put a real endpoint behind that protocol and wrapped it as an MCP tool. This
post covers what it returns, why an agent would want it, and how to plug it in.

What the endpoint does

The endpoint sells one thing: real-time cross-DEX price and spread data for
PancakeSwap v2 and v3 on BNB Smart Chain (BSC).

GET https://x402.donnyautomation.com/call?pair=WBNB/USDC
Enter fullscreen mode Exit fullscreen mode

Given a token pair (SYM/SYM, first symbol is the USD-priceable side) and an
optional PancakeSwap v3 fee tier, it returns:

  • per-venue mid prices across PancakeSwap v2 and v3 pools,
  • the best buy and best sell venue,
  • the gross cross-DEX spread in basis points,
  • per-venue and total liquidity (TVL), and
  • the source block number.

A trimmed response:

{
  "pair": "WBNB/USDC", "network": "bsc", "chainId": 56,
  "blockNumber": 107562007, "nativeUsd": 546.6,
  "pricesByVenue": [ { "venue": "pancake", "surface": "v2", "price": 546.6, "tvlUsd": 1234567 }, ... ],
  "bestBuy":  { "venue": "pancakeV3:500", "price": ... },
  "bestSell": { "venue": "biswap",        "price": ... },
  "midSpreadBps": 27.4,
  "crossDex": { "grossSpreadBps": 14.05, "buyVenue": "...", "sellVenue": "...", "surface": "v2v3" },
  "liquidity": { "venues": 7, "totalTvlUsd": ... },
  "ts": "2026-07-01T...", "source": "rpc"
}
Enter fullscreen mode Exit fullscreen mode

It costs $0.01 USDC per call on Base mainnet. The seller holds no private
key — payment settlement is handled by a facilitator, and the endpoint only
proxies to its BSC reader once payment is verified.

Why an agent needs cross-DEX spread data

Cross-DEX spread is the raw signal behind several agent tasks:

  • Arbitrage detection — a positive gross spread across venues, net of fees, is the entry condition for a two-leg trade.
  • Best-execution routing — which venue to buy from and which to sell to, right now, at this block.
  • Slippage and liquidity checks — per-venue TVL tells an agent whether a given size will move the price.

The alternative is for every agent to run BSC RPC infrastructure, maintain pool
addresses across v2 and v3 fee tiers, and re-derive constant-product and
concentrated-liquidity math. Most agents should not. One tool call, one cent, a
fresh block-stamped answer.

Using it from an MCP client

The endpoint is wrapped as a Model Context Protocol server so any MCP-capable
agent (Claude Desktop, Claude Code, and others) can call it as a tool. Install:

npm install -g bsc-dex-spread-mcp
Enter fullscreen mode Exit fullscreen mode

It is also available via Smithery
and the official MCP registry (io.github.donnywin85/bsc-dex-spread).

Then add it to your MCP client config, supplying your own buyer wallet:

{
  "mcpServers": {
    "bsc-dex-spread": {
      "command": "npx",
      "args": ["-y", "bsc-dex-spread-mcp"],
      "env": { "EVM_PRIVATE_KEY": "0xYOUR_BASE_MAINNET_BUYER_KEY" }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

A note on the wallet model, because it matters: you supply the key; the package
ships none.
The server signs each payment with the key in EVM_PRIVATE_KEY,
which you set in your own config. Fund that wallet with a few dollars of USDC on
Base and nothing else — the x402 exact scheme uses EIP-3009
transferWithAuthorization, so the facilitator broadcasts the transfer and pays
the gas. A zero-ETH wallet settles fine. Treat it as a disposable, low-balance
spending wallet.

Once configured, the agent has a get_dex_spread(pair, fee?) tool and pays
$0.01 USDC each time it calls it.

Proof it is live

The /stats page shows challenge-versus-paid counts and recent settlements, so
you can watch real demand accrue rather than take my word for it.

Takeaway

If you are building agents that touch on-chain markets, this is a small, honest
example of the pattern worth copying: a narrow, useful data endpoint, priced per
call, discoverable and payable by machines without a human in the loop. The
protocol is x402; the packaging is MCP; the price is a cent.

Top comments (0)