Quickstart
Buy agent data with x402
Discover an endpoint, receive a 402, pay $0.01 in USDC on Base, get live data. No API key. No subscription. 5 minutes start to finish.
How x402 works
The x402 protocol turns standard HTTP into a payment channel. Your agent requests data, receives payment instructions in a 402 response, pays on-chain, and retries — all autonomously.
1. GET /v1/data/:id
No payment header
→
402 Payment Required
Returns price, recipient wallet, chain ID
2. USDC transfer
Base L2, any amount ≥ asset price
→
Transaction confirmed on-chain
Get the
txHash3. GET /v1/data/:id
With X-PAYMENT header (base64)
→
200 OK + data
Payment verified on-chain before delivery
Prerequisites
What you need
- A wallet on Base L2 (mainnet)
- A small amount of USDC on Base (assets start at $0.01)
- A small amount of ETH on Base for gas (a few cents)
- Node.js 18+ (TypeScript) or Python 3.9+ (Python)
Don't have a Base wallet yet? Coinbase Wallet is the easiest way to get started — it's built on Base.
Code examples
Both examples fetch defi-yields-live — real-time DeFi yield data, refreshed every 5 minutes, priced at $0.01 USDC per call.
TypeScript — install: npm install ethers node-fetch
import fetch from 'node-fetch';
import { ethers } from 'ethers';
const ASSET_ID = 'defi-yields-live';
const BASE_RPC = 'https://mainnet.base.org';
const PRIVATE_KEY = process.env.PRIVATE_KEY!; // your Base wallet key
const USDC_ABI = [
'function transfer(address to, uint256 amount) returns (bool)',
];
async function buyData() {
// Step 1: Discover the endpoint and receive 402
const url = `https://clawmerchants.com/v1/data/${ASSET_ID}`;
const probe = await fetch(url);
if (probe.status !== 402) {
console.log(await probe.json());
return;
}
const { payment } = await probe.json() as any;
console.log(`Price: $${payment.price} USDC → ${payment.recipient}`);
// Step 2: Pay in USDC on Base L2
const provider = new ethers.JsonRpcProvider(BASE_RPC);
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
const usdc = new ethers.Contract(payment.usdcContract, USDC_ABI, wallet);
const amount = ethers.parseUnits(payment.price, 6); // USDC = 6 decimals
const tx = await usdc.transfer(payment.recipient, amount);
const receipt = await tx.wait();
console.log(`Paid: ${receipt.hash}`);
// Step 3: Include payment proof and retry
const proof = Buffer.from(JSON.stringify({
txHash: receipt.hash,
buyerWallet: wallet.address,
})).toString('base64');
const data = await fetch(url, {
headers: { 'X-PAYMENT': proof },
});
const result = await data.json() as any;
console.log('Delivered:', result.status);
console.log('Data:', JSON.stringify(result.data, null, 2));
}
buyData().catch(console.error);
Python — install: pip install httpx web3
import os, json, base64
import httpx
from web3 import Web3
ASSET_ID = 'defi-yields-live'
BASE_RPC = 'https://mainnet.base.org'
PRIVATE_KEY = os.environ['PRIVATE_KEY'] # your Base wallet key
USDC_ABI = [{
'name': 'transfer', 'type': 'function',
'inputs': [
{'name': 'to', 'type': 'address'},
{'name': 'amount', 'type': 'uint256'},
],
'outputs': [{'name': '', 'type': 'bool'}],
}]
def buy_data():
url = f'https://clawmerchants.com/v1/data/{ASSET_ID}'
# Step 1: Discover the endpoint and receive 402
probe = httpx.get(url)
if probe.status_code != 402:
print(probe.json())
return
payment = probe.json()['payment']
print(f"Price: ${payment['price']} USDC → {payment['recipient']}")
# Step 2: Pay in USDC on Base L2
w3 = Web3(Web3.HTTPProvider(BASE_RPC))
account = w3.eth.account.from_key(PRIVATE_KEY)
usdc = w3.eth.contract(address=payment['usdcContract'], abi=USDC_ABI)
amount = int(float(payment['price']) * 10**6) # USDC = 6 decimals
tx = usdc.functions.transfer(payment['recipient'], amount).build_transaction({
'from': account.address,
'nonce': w3.eth.get_transaction_count(account.address),
})
signed = account.sign_transaction(tx)
tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f"Paid: {receipt['transactionHash'].hex()}")
# Step 3: Include payment proof and retry
proof = base64.b64encode(json.dumps({
'txHash': receipt['transactionHash'].hex(),
'buyerWallet': account.address,
}).encode()).decode()
result = httpx.get(url, headers={'X-PAYMENT': proof}).json()
print('Delivered:', result['status'])
print('Data:', json.dumps(result.get('data'), indent=2))
buy_data()
Available assets
All assets follow the same x402 flow. Browse the full catalog at clawmerchants.com.
| Asset ID | Type | Price | Refresh |
|---|---|---|---|
defi-yields-live |
data | $0.01 | 5 min |
token-anomalies-live |
data | $0.01 | 5 min |
security-intel-live |
data | $0.02 | 30 min |
code-review-skill |
skill | $0.02 | — |
security-audit-skill |
skill | $0.05 | — |
What you'll see
A successful response looks like this:
JSON response — 200 OK
{
"status": "delivered",
"transactionId": "txn_abc123",
"asset": {
"id": "defi-yields-live",
"name": "DeFi Yields — Live",
"category": "crypto",
"assetType": "data"
},
"data": {
"pools": [ ... ],
"updatedAt": "2026-03-15T12:00:00.000Z"
},
"receipt": {
"amountUsdc": 0.01,
"platformFee": 0.0005,
"sellerReceived": 0.0095,
"txHash": "0xabc...",
"verifiedOnChain": true,
"timestamp": "2026-03-15T12:00:01.000Z"
}
}