Featured

Deploy OpenClaw in 60 seconds β€” 20% off logoDeploy OpenClaw in 60 seconds β€” 20% off

Launch OpenClaw on Hostinger in about 60 seconds and keep your agent live 24/7. Our referral link gives you 20% off, no coupon code needed.

Launch on Hostinger β†’
Run your Hermes agent on Hostinger, fully managed logoRun your Hermes agent on Hostinger, fully managed

Launch Hermes on Hostinger in one click, fully managed, no VPS knowledge needed. Use code ZACAARON10 for 10% off.

Launch on Hostinger β†’
Crawl and scrape any site into clean data, 10% off logoCrawl and scrape any site into clean data, 10% off

Firecrawl crawls and scrapes any site into clean markdown for your agent. Get 1,000 free credits, and new users get 10% off their first purchase.

Try Firecrawl free β†’
Your own AI agent, running 24/7 with QwikClaw logoYour own AI agent, running 24/7 with QwikClaw

QwikClaw sets up and runs an always-on OpenClaw agent for you. One click, no config files, no server setup.

Deploy now β†’
One API to scrape, enrich, and extract the internet. logoOne API to scrape, enrich, and extract the internet.

Context.dev gives your agents a single API to scrape, enrich, and extract live web data β€” no proxies, no parsers, no maintenance.

Start building free β†’
SetupClaw: done-for-you OpenClaw for founders & exec teams logoSetupClaw: done-for-you OpenClaw for founders & exec teams

White-glove OpenClaw for founders and exec teams (4–50+ employees): we install, harden, integrate your tools, and maintain it β€” secured from day one.

Get it set up for you β†’
SEO data APIs for your agent, $1 free credit logoSEO data APIs for your agent, $1 free credit

DataForSEO gives your agent live access to SERP results, keyword data, backlinks, and on-page SEO data through one API. New accounts get a $1 credit, good for up to 20,000 keyword or backlink lookups.

Try DataForSEO free β†’
Reach 47,000+ AI builders

A flat monthly placement in front of developers actively installing AI tools. No lock-in, cancel anytime.

Advertise here β†’

Works with

Claude CodeClaude DesktopCursorVS CodeClineCodex CLIOpenClaw+ any MCP client

Install to Claude Code

This server doesn't publish a one-line install command. Follow the setup in the source repository.

Summary

x402-api MCP server](https://glama.ai/mcp/servers/fernsugi/x402-api/badges/score.svg)](https://glama.ai/mcp/servers/fernsugi/x402-api) πŸ“‡ ☁️ - Pay-per-call DeFi data API for AI agents via x402 micropayments (USDC on Base).

README.md

x402 API Server

![npm: MCP Server](https://www.npmjs.com/package/@x402-api/mcp-server) ![npm: ElizaOS Plugin](https://www.npmjs.com/package/@x402-api/elizaos-plugin) ![Listed on awesome-x402](https://github.com/xpaysh/awesome-x402)

Pay-per-call crypto/DeFi data API using HTTP 402 Payment Required. No API keys. No subscriptions. AI agents pay USDC on Base, per request.

  β–ˆβ–ˆβ•—  β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—  β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
   β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•—β•šβ•β•β•β•β–ˆβ–ˆβ•—
    β•šβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•
    β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β•šβ•β•β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•
   β–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•—     β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
   β•šβ•β•  β•šβ•β•     β•šβ•β• β•šβ•β•β•β•β•β• β•šβ•β•β•β•β•β•β•

🌐 Live at: https://x402-api.fly.dev πŸ€– Agent Identity: #18763 on Base (ERC-8004) πŸ“ Blog Post: I Built a DeFi Data API Where AI Agents Pay Per Call

---

What Is This?

This is a DeFi/crypto data API server where payment is part of the HTTP protocol itself.

Every endpoint costs a small USDC micropayment β€” between 0.001 and 0.008 USDC (fractions of a cent). When a client hits a protected endpoint, the server responds with HTTP 402 Payment Required and precise payment instructions. The client pays, retries with proof, and gets data.

No accounts. No OAuth. No billing dashboard. Just: "this costs 0.003 USDC β€” pay here."

This model is designed for AI agents: autonomous software that needs to call APIs without a human reaching for a credit card. The agent holds a wallet, pays exactly what's needed, and moves on.

The stack:

  • x402 Protocol β€” HTTP 402-based micropayment standard by Coinbase
  • USDC on Base β€” L2 mainnet, sub-cent fees, instant finality
  • ERC-8004 β€” on-chain identity registration for AI agents
  • Express.js backend β€” straightforward, auditable, no framework magic

---

Endpoints

| Endpoint | Price | Description | |----------|-------|-------------| | GET /api/price-feed | 0.001 USDC | BTC/ETH/SOL prices + top 24h movers (live CoinGecko) | | GET /api/gas-tracker | 0.001 USDC | Multi-chain gas prices (ETH, Base, Polygon, Arbitrum) with speed tiers | | GET /api/dex-quotes | 0.002 USDC | Compare swap quotes across Uniswap, SushiSwap, 1inch | | GET /api/token-scanner | 0.003 USDC | Token security & risk analysis β€” rug-pull detection flags | | GET /api/whale-tracker | 0.005 USDC | Token holder concentration, Gini coefficient, whale alerts | | GET /api/yield-scanner | 0.005 USDC | Top DeFi yields across Aave, Compound, Morpho, Lido, Pendle + more | | GET /api/funding-rates | 0.008 USDC | Perp funding rates across 6 venues + arb ranking | | GET /api/wallet-profiler | 0.008 USDC | Wallet portfolio analysis, holdings, activity, risk profile | | GET /api/endpoints | Free | Machine-readable endpoint catalog | | GET /health | Free | Health check |

Query Parameters

| Endpoint | Parameter | Example | |----------|-----------|---------| | /api/dex-quotes | from, to, amount | ?from=ETH&to=USDC&amount=1.5 | | /api/token-scanner | token | ?token=PEPE or ?token=0x... | | /api/whale-tracker | token | ?token=ETH | | /api/yield-scanner | chain, min_tvl | ?chain=base&min_tvl=1000000 | | /api/funding-rates | asset | ?asset=BTC | | /api/wallet-profiler | address | ?address=0x... |

---

How x402 Works

The x402 protocol extends the long-forgotten HTTP 402 Payment Required status code into a machine-readable micropayment standard.

The Payment Flow

Step 1 β€” Initial request (no payment) ``http GET /api/price-feed HTTP/1.1 Host: x402-api.fly.dev ``

Step 2 β€” Server returns 402 ```http HTTP/1.1 402 Payment Required Content-Type: application/json

{ "x402Version": 1, "error": "Payment Required", "accepts": [{ "scheme": "exact", "network": "base", "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "payTo": "0x60264c480b67adb557efEd22Cf0e7ceA792DefB7", "maxAmountRequired": "1000", "resource": "https://x402-api.fly.dev/api/price-feed", "description": "Live crypto price feed", "extra": { "name": "USD Coin", "chainId": 8453, "supportedProofs": ["txHash"], "experimentalProofs": ["eip3009_transferWithAuthorization"] } }] } ```

Step 3 β€” Client pays and retries ``http GET /api/price-feed HTTP/1.1 Host: x402-api.fly.dev X-Payment: <base64-encoded payment proof> ``

Step 4 β€” Server verifies and responds ```http HTTP/1.1 200 OK X-Payment-Response: {"success":true,"txHash":"0x..."} Content-Type: application/json

{ "btc": 95420.12, "eth": 3241.88, ... } ```

Payment Verification

In the current repo, the production-ready payment proof path is:

  1. Transaction hash β€” Confirms a submitted Base transaction contains a USDC transfer to the receiving address.

The repo also supports EIP-3009 transferWithAuthorization settlement when you configure one of these:

  1. Direct settlement via X402_SETTLEMENT_PRIVATE_KEY β€” the server submits transferWithAuthorization on-chain and pays gas.
  2. Custom facilitator settlement via X402_FACILITATOR_URL β€” the server forwards the signed authorization to your facilitator.

Without either of those configured, the deployment stays on the txHash payment proof path only.

Receiving wallet: 0x60264c480b67adb557efEd22Cf0e7ceA792DefB7 Network: Base mainnet (chain ID 8453) Asset: USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913)

---

Using with x402-fetch

x402-fetch is the official client library from Coinbase that handles the payment flow automatically. Drop it in as a fetch replacement.

Installation

npm install x402-fetch viem

Basic Usage

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.PRIVATE_KEY as `0x${string}`);
const walletClient = createWalletClient({
  account,
  chain: base,
  transport: http(),
});

// Wrap fetch β€” payments handled automatically
const fetchWithPayment = wrapFetchWithPayment(fetch, walletClient);

// Just call the API β€” 402 is handled transparently
const response = await fetchWithPayment('https://x402-api.fly.dev/api/price-feed');
const data = await response.json();
console.log(data);

What wrapFetchWithPayment Does

  1. Makes the initial request
  2. If 402 β†’ parses payment requirements
  3. Signs the payment authorization (EIP-3009 transferWithAuthorization)
  4. Retries the request with X-Payment header
  5. Returns the successful response

Note: this is the standard x402 client flow. The current server repo also supports a simpler proof format where a client pays on-chain first, then sends a Base64 JSON X-Payment header like:

{ "txHash": "0x...", "payer": "0x..." }

Your wallet needs USDC on Base mainnet. You can bridge USDC from Ethereum to Base using the Base Bridge or buy directly on Coinbase.

---

ERC-8004 Identity

This API is registered as an AI agent on Base via ERC-8004 β€” the Ethereum standard for on-chain agent identity.

Agent ID: #18763 Registry contract: 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 Network: Base mainnet

The registration includes:

  • Agent name and description
  • Service endpoints (web + x402)
  • x402 capability flag
  • Reputation-based trust signals

This lets discovery services, AI marketplaces, and other agents find and verify this API on-chain β€” no centralized registry required.

See the registration data: agent-registration.json

---

Integrations

MCP Server (Claude Desktop / Claude API)

The MCP (Model Context Protocol) server now lives in its own standalone repo:

Quick setup:

# Run without payment (inspect mode)
npx @x402-api/mcp-server

# Run with auto-pay
X402_WALLET_PRIVATE_KEY=0x... npx @x402-api/mcp-server

Add to Claude Desktop (claude_desktop_config.json):

{
  "mcpServers": {
    "x402-api": {
      "command": "npx",
      "args": ["@x402-api/mcp-server"],
      "env": {
        "X402_WALLET_PRIVATE_KEY": "0x<your_key>"
      }
    }
  }
}

β†’ See the standalone MCP repo for full docs: x402-api-mcp-server README

ElizaOS Plugin

The elizaos-plugin/ directory contains an ElizaOS plugin that gives autonomous agents natural-language access to all 8 endpoints.

Install:

npm install @x402-api/elizaos-plugin

Register in your ElizaOS agent:

import { x402ApiPlugin } from '@x402-api/elizaos-plugin';

export const agent: Character = {
  name: 'DeFi Agent',
  plugins: [
    x402ApiPlugin({
      walletPrivateKey: process.env.X402_WALLET_PRIVATE_KEY,
    }),
  ],
};

The plugin adds 8 actions: GET_CRYPTO_PRICES, GET_GAS_PRICES, GET_DEX_QUOTES, SCAN_TOKEN, TRACK_WHALES, SCAN_YIELDS, GET_FUNDING_RATES, PROFILE_WALLET.

β†’ See elizaos-plugin/README.md for full docs.

---

Local Development

git clone https://github.com/sugi/x402-api-server
cd x402-api-server
cp .env.example .env   # defaults to development mode
npm install
npm run dev            # auto-reload on changes

In development mode (NODE_ENV=development), any non-empty X-PAYMENT header is accepted β€” no real payments needed for local testing.

# Get 402 response with payment instructions
curl -i http://localhost:4020/api/price-feed

# Test with mock payment (dev only)
curl http://localhost:4020/api/price-feed -H "X-Payment: test"

---

Architecture

src/
β”œβ”€β”€ index.js                 # Express server + graceful shutdown
β”œβ”€β”€ payment-config.js        # Settlement mode + proof support detection
β”œβ”€β”€ middleware/
β”‚   └── x402.js              # x402 payment gate middleware
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ priceFeed.js         # /api/price-feed (live CoinGecko)
β”‚   β”œβ”€β”€ gasTracker.js        # /api/gas-tracker (real RPC + mock)
β”‚   β”œβ”€β”€ dexQuotes.js         # /api/dex-quotes
β”‚   β”œβ”€β”€ tokenScanner.js      # /api/token-scanner
β”‚   β”œβ”€β”€ whaleTracker.js      # /api/whale-tracker
β”‚   β”œβ”€β”€ yieldScanner.js      # /api/yield-scanner
β”‚   β”œβ”€β”€ fundingRates.js      # /api/funding-rates
β”‚   └── walletProfiler.js    # /api/wallet-profiler
β”œβ”€β”€ services/
β”‚   └── verifier.js          # txHash verifier + EIP-3009 settlement
└── views/
    └── index.html           # Landing page

elizaos-plugin/              # @x402-api/elizaos-plugin

Standalone sibling repo:
x402-api-mcp-server/         # @x402-api/mcp-server

---

Deployment

Fly.io (recommended)

curl -L https://fly.io/install.sh | sh
fly auth login
./deploy.sh

Docker

docker compose up -d

Environment Variables

| Variable | Default | Description | |----------|---------|-------------| | PAY_TO_ADDRESS | 0x60264c...DefB7 | USDC receiving wallet on Base | | PORT | 4020 | Server port | | NODE_ENV | development | Set production for real payment verification | | BASE_RPC_URL | https://mainnet.base.org | Base RPC URL | | X402_SETTLEMENT_MODE | auto | auto, direct, facilitator, or disabled | | X402_SETTLEMENT_PRIVATE_KEY | none | Sponsor key for direct transferWithAuthorization settlement | | X402_FACILITATOR_URL | none | Custom facilitator URL for EIP-3009 settlement | | X402_FACILITATOR_API_KEY | none | Optional bearer token for your facilitator |

---

Links

---

License

MIT

See related servers & alternatives β†’

Related MCP servers

Browse all β†’

Related guides

Hand-picked reading to help you choose and use Files & Docs servers.