x402 on Base
x402 is the Coinbase-originated standard for HTTP-native micropayments. OneSource supports x402 on Base mainnet: every paid endpoint accepts a USDC-on-Base payment signature in place of an API key.
How a call works
- Your client calls a OneSource endpoint without any
Authorizationheader. - OneSource returns
HTTP 402with aPayment-Requiredheader containing the price ($0.001 – $0.010 USDC), thepayToaddress, and the asset (USDC on Base chain ID 8453). - Your client signs an EIP-712
TransferWithAuthorizationpayload over the price + nonce + deadline. - Your client retries the call with the signed payload in a
Payment-Signatureheader. - OneSource verifies the signature with the x402 facilitator, settles the transfer on Base, and returns the API response plus a
Payment-Responseheader (transaction hash + settled amount).
Total round-trip is typically under one second; the on-chain settlement is async to the response.
Using x402-fetch
x402-fetch wraps fetch to handle the 402 → sign → retry loop automatically:
import { wrapFetchWithPayment } from 'x402-fetch';
import { createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { base } from 'viem/chains';
const account = privateKeyToAccount(process.env.X402_PRIVATE_KEY as `0x${string}`);
const wallet = createWalletClient({ account, chain: base, transport: http() });
const paidFetch = wrapFetchWithPayment(fetch, wallet);
const res = await paidFetch('https://api.onesource.io/api/chain/network-info');
const { data, error } = await res.json();
The wrapper handles every paid endpoint transparently: you call it like normal fetch.
Using AgentCash
AgentCash is an agent wallet and MCP server that speaks both x402 and MPP. Set it up with:
npx agentcash@latest install
It generates a local wallet on first run; fund it with USDC on Base. Once AgentCash is wired into your assistant (see its setup docs), ask the assistant to fetch https://api.onesource.io/api/chain/network-info and it signs the x402 payment automatically.
Using the OneSource MCP Server with x402
Set X402_PRIVATE_KEY instead of ONESOURCE_API_KEY:
X402_PRIVATE_KEY=0x… npx -y @one-source/mcp@latest
Or in your MCP client config:
{
"mcpServers": {
"onesource": {
"command": "npx",
"args": ["-y", "@one-source/mcp@latest"],
"env": { "X402_PRIVATE_KEY": "0x…" }
}
}
}
The OneSource MCP Server picks up the key and signs payments automatically on every tool call.
To batch many calls through one channel instead of paying per call, add X402_PAYMENT_MODE=batch (and a persistent X402_CHANNEL_DIR): see Batch settlement below.
Pricing
Per-call USDC prices are published in two places:
- The
x-payment-info.price.amountextension on every API Reference page. - The response
meta.cost_usdcfield on every successful call.
Examples:
| Endpoint | Price (USDC) |
|---|---|
/api/chain/block-number | 0.001 |
/api/chain/network-info | 0.001 |
/api/chain/live-balance | 0.003 |
/api/chain/call | 0.005 |
/api/chain/nft-metadata | 0.008 |
/api/chain/pending | 0.010 |
Verify the payment
The Payment-Response header on a successful call carries the on-chain transaction hash. You can verify settlement on https://basescan.org with that hash.
Receipts
OneSource also returns settlement metadata on the body's meta object: payment_chain, payment_token, cost_usdc, request_id. Log these for audit / billing reconciliation.
Batch settlement
x402 has a session-like mode that mirrors MPP sessions, but stays on Base/USDC, so you don't bridge to Tempo. Instead of settling every call on-chain, you open a payment channel with a single deposit, satisfy many calls with off-chain signed claims against it, and OneSource settles the cumulative total in batched on-chain claims. For high call volumes this amortizes settlement gas the same way MPP sessions do.
OneSource advertises a batch-settlement scheme alongside the standard exact scheme in the 402 for every /api/chain/* route. OneSource is the channel authorizer (self-managed), claims accrued usage on a short interval, and refunds any unused deposit after a withdraw delay (~1 day on mainnet).
Using it
Batch needs a client that holds channel state across calls: the deposit, the signed vouchers, and the running cumulative total. Two supported paths:
- The OneSource MCP Server (no code). Set
X402_PAYMENT_MODE=batch(and a persistentX402_CHANNEL_DIR) when you run@one-source/mcpin x402 mode, or flip it in-session with the1s_payment_modetool. The1s_refundtool reclaims any unused deposit on demand when you're done. See MCP configuration → Batch settlement. Works in the default stdio (long-lived) transport, not the stateless--httpmode. - A custom client. Build directly on the
@x402/evmSDK. Build an x402 batch-settlement client is a complete, runnable example you can copy.
The common third-party x402 clients (x402-fetch, AgentCash, the Coinbase agentic wallet (awal)) implement only the exact scheme. They ignore the batch challenge and keep paying per call, unchanged, so nothing breaks. Batch today means either the OneSource MCP Server's batch mode or a custom batch-settlement client. Protocol details: the x402 batch-settlement spec.
Next
- MPP on Tempo: alternative protocol with lower gas costs
- Wallet setup: if you haven't funded your wallet yet