A pay-per-call swap API for onchain agents. The caller signs a single x402 payment in USDC — no ETH, no approvals, no key sharing. fold sponsors the gas and routes the swap; the output token lands directly in the caller's wallet.
/swapPOST with tokenOut, amountUsdc, recipient. The first response is HTTP 402 with payment terms.
A single EIP-3009 signature in USDC. No gas, no on-chain approval — the private key never leaves the agent.
The payment settles first, then fold runs the swap through an aggregator and sends the output token straight to recipient. Gas fully sponsored.
# 1) hit the endpoint — receive 402 payment terms curl -X POST https://x402.fold.computer/swap \ -H "Content-Type: application/json" \ -d '{"tokenOut":"0x4200...0006","amountUsdc":1.0,"recipient":"0xYOURADDR"}' # 2) re-send with the signed x402 PAYMENT-SIGNATURE header # any x402 client does this for you — see the typescript tab
import { x402Client, wrapFetchWithPayment } from "@x402/fetch" import { ExactEvmScheme } from "@x402/evm/exact/client" const client = new x402Client() client.register("eip155:*", new ExactEvmScheme(signer)) const pay = wrapFetchWithPayment(fetch, client) const res = await pay("https://x402.fold.computer/swap", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ tokenOut: "0x4200000000000000000000000000000000000006", // WETH amountUsdc: 1.0, // swap amount + 0.01 fee recipient: signer.address, // where the token lands }), }) // agent holds zero ETH — token arrives in recipient's wallet
| field | type | description |
|---|---|---|
tokenOut required | address | Base token to receive (any aggregator-liquid token) |
amountUsdc required | number | Total USDC to pay — swap amount plus a 0.01 fee |
recipient required | address | Where the output token is sent |