← 返回
未分类 中文

x402 Quickstart

Deploy x402 pay-per-call API endpoints in minutes. Turn any OpenClaw skill or service into a monetized endpoint accepting USDC on Base. Includes payment veri...
在几分钟内部署 x402 按调用付费 API端点,将任意 OpenClaw 技能或服务转为接受 Base 上 USDC 的付费端点,包含支付验证。
jimmyclanker
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 351
下载
💾 0
安装
1
版本
#latest

概述

x402 Quickstart

Deploy x402-compatible pay-per-call endpoints that accept USDC payments from AI agents on Base.

What is x402?

HTTP 402 ("Payment Required") is the standard for machine-to-machine payments. An agent sends a request, gets a 402 response with pricing info, pays in USDC on Base, and receives the data. No API keys, no accounts, no subscriptions.

Ecosystem (Q1 2026): Stripe, Cloudflare, Google (AP2), Coinbase all ship native x402 support.

Quick Deploy

1. Generate endpoint scaffold

bash scripts/scaffold.sh my-service "My cool API" 0.01

Creates a ready-to-run Express server with x402 payment middleware at ./my-service/.

2. Configure wallet

Set your Base wallet address to receive payments:

# In the generated .env file
WALLET_ADDRESS=0xYourBaseWalletAddress
USDC_CONTRACT=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
CHAIN_ID=8453
PORT=3402

3. Run locally

cd my-service && npm install && node server.js

4. Expose via Cloudflare Tunnel (zero cost)

cloudflared tunnel --url http://localhost:3402

How It Works

Agent Flow

Agent → GET /api/data → 402 Payment Required
                         ├── price: "0.01 USDC"
                         ├── payTo: "0x..."
                         └── network: "base"
Agent → pays USDC on Base → gets tx hash
Agent → GET /api/data (X-Payment-Tx: 0x...) → 200 OK + data

Server Flow

  1. Request arrives without payment → respond 402 with pricing
  2. Request arrives with X-Payment-Tx header → verify on-chain
  3. If payment confirmed → serve data
  4. If payment fails → respond 402 again

Endpoint Ideas

High-value endpoints AI agents will pay for:

EndpointPriceDescription
------------------------------
/alpha/scan$0.50-1.00Token/project analysis with scoring
/market/signal$0.10Real-time trading signals
/research/report$1.00Deep research on any topic
/data/portfolio$0.05Multi-chain portfolio snapshot
/tools/scrape$0.02Clean web content extraction
/ai/inference$0.04LLM inference routing

Payment Verification

The scaffold includes scripts/verify-payment.js for on-chain verification:

// Verifies USDC transfer on Base
const verified = await verifyPayment(txHash, expectedAmount, recipientAddress);

Uses Base RPC (free tier) — no API key needed for basic verification.

Integration with OpenClaw

As a skill endpoint

Add to your agent's capabilities:

// In SKILL.md or agent config
{
  tools: [{
    name: "my_x402_service",
    endpoint: "https://my-service.example.com/api",
    payment: { currency: "USDC", network: "base" }
  }]
}

With Cloudflare Tunnel

Zero-cost hosting on your existing machine:

# One-time setup
cloudflared tunnel create my-x402
cloudflared tunnel route dns my-x402 api.mydomain.com

# Run
cloudflared tunnel run --url http://localhost:3402 my-x402

Spraay Gateway Integration

Register your endpoint on Spraay to get discovered by agents automatically:

curl -X POST https://gateway.spraay.app/register \
  -H "Content-Type: application/json" \
  -d '{"url": "https://api.mydomain.com", "category": "data", "price": "0.01"}'

Pricing Strategy

  • Data endpoints: $0.005-0.05 (commodity, high volume)
  • Analysis endpoints: $0.10-1.00 (value-add, medium volume)
  • Research endpoints: $1.00-5.00 (premium, low volume)
  • GPU/compute: $0.05-0.50 (resource-based pricing)

Start low, raise prices when you have traction. Better to have 1000 calls at $0.01 than 0 calls at $1.00.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 10:35 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-intelligence

Roundtable Adaptive

jimmyclanker
自适应多模型AI圆桌。运行多达4个AI模型(可配置),进行2轮辩论,含交叉批判与正式共识评分。需消耗……
★ 0 📥 1,223

Task Router

jimmyclanker
自动将任务路由至合适的工具、代理或工作流;分析任务意图和复杂度后路由至编码、研究、交易、系统等。
★ 0 📥 384

Multichain Portfolio Tracker

jimmyclanker
多链加密货币投资组合追踪,实时价格、盈亏及提醒,支持 EVM(以太坊、Base、Arbitrum、Polygon、Optimism)、Solana 以及手动输入。
★ 0 📥 352