pay-for-service

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Making Paid x402 Requests

发起付费x402请求

Use the
npx awal@latest x402 pay
command to call paid API endpoints with automatic USDC payment on Base.
使用
npx awal@latest x402 pay
命令在Base网络上调用带有自动USDC支付的付费API端点。

Confirm wallet is initialized and authed

确认钱包已初始化并完成认证

bash
npx awal@latest status
If the wallet is not authenticated, refer to the
authenticate-wallet
skill.
bash
npx awal@latest status
如果钱包未认证,请参考
authenticate-wallet
技能。

Command Syntax

命令语法

bash
npx awal@latest x402 pay <url> [-X <method>] [-d <json>] [-q <params>] [-h <json>] [--max-amount <n>] [--json]
bash
npx awal@latest x402 pay <url> [-X <method>] [-d <json>] [-q <params>] [-h <json>] [--max-amount <n>] [--json]

Options

选项

OptionDescription
-X, --method <method>
HTTP method (default: GET)
-d, --data <json>
Request body as JSON string
-q, --query <params>
Query parameters as JSON string
-h, --headers <json>
Custom HTTP headers as JSON string
--max-amount <amount>
Max payment in USDC atomic units (1000000 = $1.00)
--correlation-id <id>
Group related operations
--json
Output as JSON
选项描述
-X, --method <method>
HTTP方法(默认:GET)
-d, --data <json>
请求体(JSON字符串格式)
-q, --query <params>
查询参数(JSON字符串格式)
-h, --headers <json>
自定义HTTP头(JSON字符串格式)
--max-amount <amount>
最大支付金额(USDC原子单位,1000000 = 1.00美元)
--correlation-id <id>
分组相关操作
--json
以JSON格式输出

USDC Amounts

USDC金额

X402 uses USDC atomic units (6 decimals):
Atomic UnitsUSD
1000000$1.00
100000$0.10
50000$0.05
10000$0.01
IMPORTANT: Always single-quote amounts that use
$
to prevent bash variable expansion (e.g.
'$1.00'
not
$1.00
).
x402使用USDC原子单位(6位小数):
原子单位美元
1000000$1.00
100000$0.10
50000$0.05
10000$0.01
重要提示:对于包含
$
的金额,请始终使用单引号包裹,以避免bash变量展开(例如使用
'$1.00'
而非
$1.00
)。

Examples

示例

bash
undefined
bash
undefined

Make a GET request (auto-pays)

发起GET请求(自动支付)

npx awal@latest x402 pay https://example.com/api/weather
npx awal@latest x402 pay https://example.com/api/weather

Make a POST request with body

发起带请求体的POST请求

npx awal@latest x402 pay https://example.com/api/sentiment -X POST -d '{"text": "I love this product"}'
npx awal@latest x402 pay https://example.com/api/sentiment -X POST -d '{"text": "I love this product"}'

Limit max payment to $0.10

将最大支付金额限制为0.10美元

npx awal@latest x402 pay https://example.com/api/data --max-amount 100000
undefined
npx awal@latest x402 pay https://example.com/api/data --max-amount 100000
undefined

Prerequisites

前提条件

  • Must be authenticated (
    npx awal@latest status
    to check, see
    authenticate-wallet
    skill)
  • Wallet must have sufficient USDC balance (
    npx awal@latest balance
    to check)
  • If you don't know the endpoint URL, use the
    search-for-service
    skill to find services first
  • 必须已完成认证(使用
    npx awal@latest status
    检查,参考
    authenticate-wallet
    技能)
  • 钱包必须有足够的USDC余额(使用
    npx awal@latest balance
    检查)
  • 若不知道端点URL,请先使用
    search-for-service
    技能查找服务

Error Handling

错误处理

  • "Not authenticated" - Run
    awal auth login <email>
    first, or see
    authenticate-wallet
    skill
  • "No X402 payment requirements found" - URL may not be an x402 endpoint; use
    search-for-service
    to find valid endpoints
  • "Insufficient balance" - Fund wallet with USDC; see
    fund
    skill
  • "Not authenticated" - 先运行
    awal auth login <email>
    ,或参考
    authenticate-wallet
    技能
  • "No X402 payment requirements found" - 该URL可能不是x402端点;使用
    search-for-service
    查找有效端点
  • "Insufficient balance" - 为钱包充值USDC;参考
    fund
    技能