x402-client
Make paid API requests using the x402 HTTP payment protocol (USDC on Base Sepolia). Use when you need to access x402-protected services, pay for API calls with crypto, or perform web searches via an x402 search gateway. Handles wallet setup, payment signing, and request retry automatically.
- License 许可
- AGPL-3.0
- 最近更新
- 2026-11-13
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- x402-client
- description
- Make paid API requests using the x402 HTTP payment protocol (USDC on Base Sepolia). Use when you need to access x402-protected services, pay for API calls with crypto, or perform web searches via an x402 search gateway. Handles wallet setup, payment signing, and request retry automatically.
02 资源文件 8
- 参考文档_meta.json138 B
- 参考文档references/services.md1.0 KB
- 脚本scripts/setup.sh1.0 KB
- 脚本scripts/wallet-gen.mjs1.1 KB
- 脚本scripts/x402-fetch.mjs3.5 KB
- 参考文档skill-card.md2.2 KB
- 参考文档SOURCE.md266 B
- 参考文档TRUST.auto.yaml2.3 KB
03 SKILL.md 正文
x402 Client
Make HTTP requests to x402-protected APIs. The x402 protocol uses HTTP 402 responses to request payment — this skill handles signing USDC payments and retrying automatically.
Prerequisites
- Node.js 18+ installed
- A Base Sepolia wallet with ETH (gas) and USDC (payments)
First-Time Setup
1. Install dependencies
bash <skill-dir>/scripts/setup.sh
This installs the x402 SDK to ~/.x402-client/. Only needed once.
2. Generate a wallet (if you don't have one)
node <skill-dir>/scripts/wallet-gen.mjs --out ~/.x402-client/wallet.key
3. Fund the wallet
Get testnet tokens from faucets:
- Base Sepolia ETH (gas): https://www.alchemy.com/faucets/base-sepolia
- Base Sepolia USDC (payments): https://faucet.circle.com/ → select Base Sepolia + USDC
Send both to the wallet address printed by wallet-gen.
4. Store the key
Set the environment variable for future use:
export X402_PRIVATE_KEY=$(cat ~/.x402-client/wallet.key)
Or pass --key-file ~/.x402-client/wallet.key to each request.
Making Paid Requests
Use x402-fetch.mjs to make any x402-paid HTTP request:
# Search the web ($0.001 USDC per query)
node <skill-dir>/scripts/x402-fetch.mjs \
"https://<service-url>/web/search?q=latest+AI+news&count=5" \
--key-file ~/.x402-client/wallet.key
The script automatically:
- Makes the HTTP request
- If 402 received, parses payment requirements
- Signs a USDC payment with your wallet
- Retries with the payment header
- Outputs the response JSON to stdout
All scripts must be run from ~/.x402-client/ (where node_modules lives):
cd ~/.x402-client && node <skill-dir>/scripts/x402-fetch.mjs "<url>" --key-file wallet.key
Known Services
See references/services.md for a list of known x402 endpoints including a web search service.
Troubleshooting
- "insufficient funds": Wallet needs more USDC or ETH. Use faucets above.
- 402 with no auto-payment: Ensure setup.sh was run and you're executing from
~/.x402-client/. - Tunnel URL not working: The service URL may have changed. Ask the service operator or check
/health.
04 同仓库更多 Skills
recipe-performance
Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold/warm/background-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout/paint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.
mexc-spot-websocket
MEXC Spot WebSocket workflows for public streams, protobuf handling, depth maintenance, listen keys, and private streams without exposing API keys.
mexc-spot-rest
MEXC Spot REST workflows for public data, signed account requests, orders, wallet/admin actions, and secure signing without exposing API keys.
mexc-futures-websocket
MEXC Futures WebSocket workflows for public streams, private account/order/position streams, ping/pong, subscriptions, and depth maintenance.
0xklen-version-and-refresh-sanctions-lists
暂无简介
verify-tests-cover-changed-lines
Use when a PR adds code that the existing suite may not exercise. Measures patch coverage — the share of newly changed lines hit by tests — before approving.