Making Paid x402 Requests
Use the npx awal@latest x402 pay command to call paid API endpoints with automatic USDC payment on Base.
Confirm wallet is initialized and authed
CODEBLOCK0
If the wallet is not authenticated, refer to the authenticate-wallet skill.
Command Syntax
CODEBLOCK1
Options
| Option | Description |
|---|
| INLINECODE2 | HTTP method (default: GET) |
| INLINECODE3 |
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 |
USDC Amounts
X402 uses USDC atomic units (6 decimals):
| Atomic Units | USD |
|---|
| 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).
Examples
CODEBLOCK2
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
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
技能名称: pay-for-service
详细描述:
发起付费 x402 请求
使用 npx awal@latest x402 pay 命令调用付费 API 端点,并通过 Base 网络自动完成 USDC 支付。
确认钱包已初始化并认证
bash
npx awal@latest status
如果钱包未认证,请参考 authenticate-wallet 技能。
命令语法
bash
npx awal@latest x402 pay [-X ] [-d ] [-q ] [-h ] [--max-amount ] [--json]
选项
| 选项 | 描述 |
|---|
| -X, --method <method> | HTTP 方法(默认:GET) |
| -d, --data <json> |
请求体,JSON 字符串格式 |
| -q, --query
| 查询参数,JSON 字符串格式 |
| -h, --headers | 自定义 HTTP 请求头,JSON 字符串格式 |
| --max-amount | 最大支付金额,USDC 原子单位(1000000 = $1.00) |
| --correlation-id | 对相关操作进行分组 |
| --json | 以 JSON 格式输出 |
USDC 金额
X402 使用 USDC 原子单位(6 位小数):
$0.10 |
| 50000 | $0.05 |
| 10000 | $0.01 |
重要提示:对于包含 $ 的金额,务必使用单引号包裹,以防止 bash 变量展开(例如使用 $1.00 而非 $1.00)。
示例
bash
发起 GET 请求(自动支付)
npx awal@latest x402 pay https://example.com/api/weather
发起带请求体的 POST 请求
npx awal@latest x402 pay https://example.com/api/sentiment -X POST -d {text: I love this product}
限制最大支付金额为 $0.10
npx awal@latest x402 pay https://example.com/api/data --max-amount 100000
前置条件
- - 必须完成认证(使用 npx awal@latest status 检查,详见 authenticate-wallet 技能)
- 钱包必须有足够的 USDC 余额(使用 npx awal@latest balance 检查)
- 如果不知道端点 URL,请先使用 search-for-service 技能查找服务
错误处理
- - Not authenticated(未认证) - 请先运行 awal auth login ,或参考 authenticate-wallet 技能
- No X402 payment requirements found(未找到 X402 支付要求) - 该 URL 可能不是 x402 端点;请使用 search-for-service 查找有效端点
- Insufficient balance(余额不足) - 请向钱包充值 USDC;详见 fund 技能