x402
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesex402 Payment Protocol
x402支付协议
Use the commands to discover, inspect, and call paid API endpoints using the X402 payment protocol. Payments are made in USDC on Base.
npx awal@latest x402使用命令,通过X402支付协议发现、查看并调用付费API端点。支付以Base网络上的USDC进行。
npx awal@latest x402Workflow
工作流程
The typical x402 workflow is:
- Find a service - Search the bazaar or get details for a known endpoint
- Check requirements - Inspect price, method, and input schema
- Make the request - Call the endpoint with automatic USDC payment
典型的x402工作流程如下:
- 查找服务 - 搜索集市,或获取已知端点的详细信息
- 查看要求 - 检查价格、请求方法和输入 schema
- 发起请求 - 调用端点并自动完成USDC支付
Commands
命令
Search the Bazaar
搜索集市
Find paid services by keyword using BM25 relevance search:
bash
npx awal@latest x402 bazaar search <query> [-k <n>] [--force-refresh] [--json]| Option | Description |
|---|---|
| Number of results (default: 5) |
| Re-fetch resource index from CDP API |
| Output as JSON |
Results are cached locally at and auto-refresh after 12 hours.
~/.config/awal/bazaar/通过BM25相关性搜索,按关键词查找付费服务:
bash
npx awal@latest x402 bazaar search <query> [-k <n>] [--force-refresh] [--json]| 选项 | 描述 |
|---|---|
| 结果数量(默认值:5) |
| 从CDP API重新获取资源索引 |
| 以JSON格式输出 |
结果会缓存在本地目录,12小时后自动刷新。
~/.config/awal/bazaar/List Bazaar Resources
列出集市资源
Browse all available resources:
bash
awal x402 bazaar list [--network <network>] [--full] [--json]| Option | Description |
|---|---|
| Filter by network (base, base-sepolia) |
| Show complete details including schemas |
| Output as JSON |
浏览所有可用资源:
bash
awal x402 bazaar list [--network <network>] [--full] [--json]| 选项 | 描述 |
|---|---|
| 按网络筛选(base, base-sepolia) |
| 显示完整详情,包括schema |
| 以JSON格式输出 |
Discover Payment Requirements
了解支付要求
Inspect an endpoint's x402 payment requirements without paying:
bash
awal x402 details <url> [--json]Auto-detects the correct HTTP method (GET, POST, PUT, DELETE, PATCH) by trying each until it gets a 402 response, then displays price, accepted payment schemes, network, and input/output schemas.
无需支付即可查看端点的x402支付要求:
bash
awal x402 details <url> [--json]会自动检测正确的HTTP方法(GET、POST、PUT、DELETE、PATCH),直到获取到402响应,然后显示价格、支持的支付方案、网络以及输入/输出schema。
Make a Paid Request
发起付费请求
Call an x402 endpoint with automatic USDC payment:
bash
awal x402 pay <url> [-X <method>] [-d <json>] [-q <params>] [-h <json>] [--max-amount <n>] [--json]| Option | Description |
|---|---|
| HTTP method (default: GET) |
| Request body as JSON string |
| Query parameters as JSON string |
| Custom HTTP headers as JSON string |
| Max payment in USDC atomic units (1000000 = $1.00) |
| Group related operations |
| Output as JSON |
调用x402端点并自动完成USDC支付:
bash
awal x402 pay <url> [-X <method>] [-d <json>] [-q <params>] [-h <json>] [--max-amount <n>] [--json]| 选项 | 描述 |
|---|---|
| HTTP方法(默认值:GET) |
| 请求体(JSON字符串格式) |
| 查询参数(JSON字符串格式) |
| 自定义HTTP头(JSON字符串格式) |
| 最大支付金额(USDC原子单位,1000000 = $1.00) |
| 分组相关操作 |
| 以JSON格式输出 |
Examples
示例
bash
undefinedbash
undefinedSearch for weather-related paid APIs
搜索天气相关的付费API
awal x402 bazaar search "weather"
awal x402 bazaar search "weather"
Search with more results
搜索并获取更多结果
awal x402 bazaar search "sentiment analysis" -k 10
awal x402 bazaar search "sentiment analysis" -k 10
Check what an endpoint costs
查看端点的费用
awal x402 details https://example.com/api/weather
awal x402 details https://example.com/api/weather
Make a GET request (auto-pays)
发起GET请求(自动支付)
awal x402 pay https://example.com/api/weather
awal x402 pay https://example.com/api/weather
Make a POST request with body
发起带请求体的POST请求
awal x402 pay https://example.com/api/sentiment -X POST -d '{"text": "I love this product"}'
awal x402 pay https://example.com/api/sentiment -X POST -d '{"text": "I love this product"}'
Limit max payment to $0.10
将最大支付金额限制为0.10美元
awal x402 pay https://example.com/api/data --max-amount 100000
awal x402 pay https://example.com/api/data --max-amount 100000
Browse all bazaar resources with full details
浏览集市所有资源并查看完整详情
awal x402 bazaar list --full
undefinedawal x402 bazaar list --full
undefinedUSDC Amounts
USDC金额
X402 uses USDC atomic units (6 decimals):
| Atomic Units | USD |
|---|---|
| 1000000 | $1.00 |
| 100000 | $0.10 |
| 50000 | $0.05 |
| 10000 | $0.01 |
X402使用USDC原子单位(6位小数):
| 原子单位 | 美元 |
|---|---|
| 1000000 | $1.00 |
| 100000 | $0.10 |
| 50000 | $0.05 |
| 10000 | $0.01 |
Prerequisites
前提条件
- Search/Details: No authentication needed
- Pay: Must be authenticated () with sufficient USDC balance (
awal auth login <email>)awal balance
- 搜索/查看详情:无需认证
- 支付:必须完成认证(),且USDC余额充足(可通过
awal auth login <email>查看)awal balance
Error Handling
错误处理
- "Not authenticated" - Run first
awal auth login <email> - "No X402 payment requirements found" - URL may not be an x402 endpoint
- "CDP API returned 429" - Rate limited; cached data will be used if available
- "Insufficient balance" - Fund wallet with USDC (to check)
awal balance
- "Not authenticated" - 先运行
awal auth login <email> - "No X402 payment requirements found" - 该URL可能不是x402端点
- "CDP API returned 429" - 触发速率限制;若有缓存数据则使用缓存
- "Insufficient balance" - 为钱包充值USDC(可通过查看余额)
awal balance