██╗ ██╗██╗ ██╗ ██████╗ ██████╗ █████╗ ██████╗ ██╗ ╚██╗██╔╝██║ ██║██╔═══██╗╚════██╗ ██╔══██╗██╔══██╗██║ ╚███╔╝ ███████║██║ ██║ █████╔╝ ─── ███████║██████╔╝██║ ██╔██╗ ╚════██║██║ ██║██╔═══╝ ██╔══██║██╔═══╝ ██║ ██╔╝ ██╗ ██║╚██████╔╝███████╗ ██║ ██║██║ ██║ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
| Method | Endpoint | Price | Description | Data |
|---|---|---|---|---|
| GET | /api/price-feed | 0.001 USDC | BTC, ETH, SOL prices + top 5 movers/losers by 24h change. 60s server cache. | LIVE ✓ |
| GET | /api/gas-tracker | 0.001 USDC | Gas prices on Ethereum, Base, Polygon, Arbitrum — slow/normal/fast tiers + USD cost estimates. | LIVE ✓ |
| GET | /api/dex-quotes | 0.002 USDC | Swap quotes across Uniswap V3, SushiSwap, 1inch. Price impact, fees, route. ?from=ETH&to=USDC&amount=1 |
LIVE ✓ |
| GET | /api/token-scanner | 0.003 USDC | Token security analysis: contract verification, honeypot check, liquidity lock, mint function, risk score. ?token=PEPE |
LIVE ✓ |
| GET | /api/whale-tracker | 0.005 USDC | Holder concentration: Gini coefficient, Herfindahl index, top 20 holders, large transfer alerts. ?token=ETH |
LIVE ✓ |
| GET | /api/yield-scanner | 0.005 USDC | Top DeFi yields across Aave, Compound, Morpho, Lido, Pendle, Ethena. Filter by chain, asset, TVL. | LIVE ✓ |
| GET | /api/funding-rates | 0.008 USDC | Perp funding rates on Hyperliquid, dYdX v4, Aevo, GMX, Drift, Vertex + arb spread ranking. | LIVE ✓ |
| GET | /api/wallet-profiler | 0.008 USDC | Wallet portfolio: holdings, DeFi positions, activity metrics, risk classification. ?address=0x… |
LIVE ✓ |
| GET | /health | FREE | Server health check · returns status, uptime, pay-to address | FREE |
Use x402-fetch (the official Coinbase x402 client) to automatically handle
the payment flow. No manual header wrangling — it intercepts 402s, signs USDC transfers on Base, and retries.
import { withPaymentInterceptor } from 'x402-fetch'; import { createWalletClient, http } from 'viem'; import { base } from 'viem/chains'; import { privateKeyToAccount } from 'viem/accounts'; // 1. Configure wallet with USDC on Base const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`); const walletClient = createWalletClient({ account, chain: base, transport: http(), }); // 2. Wrap fetch with x402 payment interceptor const fetchWithPayment = withPaymentInterceptor(fetch, walletClient); // 3. Call endpoints — payment happens automatically on 402 const res = await fetchWithPayment( 'https://x402-api.fly.dev/api/price-feed' ); const { data } = await res.json(); console.log('BTC:', data.core[0].price_usd); // e.g. 98000 console.log('ETH:', data.core[1].price_usd); // e.g. 2750 // Other endpoints — same pattern, different prices const gas = await ( await fetchWithPayment('https://x402-api.fly.dev/api/gas-tracker') ).json(); console.log('ETH gas (normal):', gas.data.ethereum.gas_price_gwei.normal, 'gwei'); const yields = await ( await fetchWithPayment( 'https://x402-api.fly.dev/api/yield-scanner?chain=base&min_tvl=1000000' ) ).json(); console.log('Top yield:', yields.data[0].protocol, yields.data[0].apy + '%');
from x402.client import X402Client from eth_account import Account # 1. Load your private key account = Account.from_key(os.environ["PRIVATE_KEY"]) # 2. Create client (auto-handles 402 → pay → retry) client = X402Client( account=account, chain_id=8453, # Base mainnet rpc_url="https://mainnet.base.org", ) # 3. Fetch prices — payment deducted automatically data = client.get("https://x402-api.fly.dev/api/price-feed") print(f"BTC: ${data['data']['core'][0]['price_usd']:,.0f}") # Token security scan scan = client.get( "https://x402-api.fly.dev/api/token-scanner", params={"token": "PEPE", "chain": "ethereum"} ) print(f"PEPE risk: {scan['data']['risk_level']} ({scan['data']['risk_score']}/100)")
# Step 1: Probe — get payment requirements (returns 402) curl -s https://x402-api.fly.dev/api/price-feed | jq . # Response: 402 Payment Required { "x402Version": 1, "error": "Payment Required", "accepts": [{ "scheme": "exact", "network": "base", "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "payTo": "0x60264c480b67adb557efEd22Cf0e7ceA792DefB7", "maxAmountRequired": "1000" }] } # Step 2: Sign EIP-3009 transferWithAuthorization on Base # (use x402-fetch or Coinbase SDK — do not do this by hand in prod) # Step 3: Retry with X-Payment header (base64 JSON payload) curl -s https://x402-api.fly.dev/api/price-feed \ -H "X-Payment: <base64-encoded-payment-payload>" | jq .data.core # Response: 200 OK — live crypto prices [ { "id": "bitcoin", "price_usd": 98000, "change_24h_pct": 2.1 }, { "id": "ethereum", "price_usd": 2750, "change_24h_pct": -0.8 }, { "id": "solana", "price_usd": 185, "change_24h_pct": 4.2 } ]
// DeFi scout agent — scans for arb opportunities using x402-api const BASE_URL = 'https://x402-api.fly.dev'; async function defiScout() { // Pay 0.008 USDC — get funding rate arb opportunities const { arb_opportunities } = await ( await fetchWithPayment(`${BASE_URL}/api/funding-rates?asset=ETH`) ).json(); const strong = arb_opportunities.filter(o => o.signal === 'STRONG'); if (!strong.length) return console.log('No strong arb opportunities.'); const best = strong[0]; console.log(`🎯 ${best.asset}: long ${best.long_venue}, short ${best.short_venue}`); console.log(` Spread: ${best.spread_bps}bps · APR: ${best.annualized_arb_pct}%`); // Pay 0.008 USDC — check gas before execution const { data: gas } = await ( await fetchWithPayment(`${BASE_URL}/api/gas-tracker`) ).json(); console.log(`⛽ Arbitrum gas: ${gas.arbitrum.gas_price_gwei.fast} gwei fast`); } defiScout(); // Total cost per run: 0.001 + 0.008 = 0.009 USDC (~$0.009)
{
"x402Version": 1,
"error": "Payment Required",
"accepts": [{
"scheme": "exact",
"network": "base",
"asset": "0x833589fC...",
"payTo": "0x60264c48...",
"maxAmountRequired": "1000",
"extra": { "chainId": 8453 }
}]
}
{
"timestamp": "2026-02-22T09:35:00Z",
"source": "CoinGecko",
"payment": {
"verified": true,
"amount": "1000"
},
"data": {
"core": [
{ "id": "bitcoin",
"price_usd": 98000,
"change_24h_pct": 2.1 }
]
}
}