$npx -y skills add basezh/agent-skills-on-base --skill pay-for-serviceMake a paid API request to an x402 endpoint with automatic USDC payment. Use when you or the user want to call a paid API, make an x402 request, use a paid service, or pay for an API call. Use after finding a service with search-for-service.
| 1 | # Making Paid x402 Requests |
| 2 | |
| 3 | Use the `npx awal@2.0.3 x402 pay` command to call paid API endpoints with automatic USDC payment on Base. |
| 4 | |
| 5 | ## Confirm wallet is initialized and authed |
| 6 | |
| 7 | ```bash |
| 8 | npx awal@2.0.3 status |
| 9 | ``` |
| 10 | |
| 11 | If the wallet is not authenticated, refer to the `authenticate-wallet` skill. |
| 12 | |
| 13 | ## Command Syntax |
| 14 | |
| 15 | ```bash |
| 16 | npx awal@2.0.3 x402 pay <url> [-X <method>] [-d <json>] [-q <params>] [-h <json>] [--max-amount <n>] [--json] |
| 17 | ``` |
| 18 | |
| 19 | ## Options |
| 20 | |
| 21 | | Option | Description | |
| 22 | | ----------------------- | -------------------------------------------------- | |
| 23 | | `-X, --method <method>` | HTTP method (default: GET) | |
| 24 | | `-d, --data <json>` | Request body as JSON string | |
| 25 | | `-q, --query <params>` | Query parameters as JSON string | |
| 26 | | `-h, --headers <json>` | Custom HTTP headers as JSON string | |
| 27 | | `--max-amount <amount>` | Max payment in USDC atomic units (1000000 = $1.00) | |
| 28 | | `--correlation-id <id>` | Group related operations | |
| 29 | | `--json` | Output as JSON | |
| 30 | |
| 31 | ## USDC Amounts |
| 32 | |
| 33 | X402 uses USDC atomic units (6 decimals): |
| 34 | |
| 35 | | Atomic Units | USD | |
| 36 | | ------------ | ----- | |
| 37 | | 1000000 | $1.00 | |
| 38 | | 100000 | $0.10 | |
| 39 | | 50000 | $0.05 | |
| 40 | | 10000 | $0.01 | |
| 41 | |
| 42 | **IMPORTANT**: Always single-quote amounts that use `$` to prevent bash variable expansion (e.g. `'$1.00'` not `$1.00`). |
| 43 | |
| 44 | ## Input Validation |
| 45 | |
| 46 | Before constructing the command, validate all user-provided values to prevent shell injection: |
| 47 | |
| 48 | - **url**: Must be a valid URL starting with `https://` or `http://`. Reject if it contains spaces, semicolons, pipes, backticks, or shell metacharacters. |
| 49 | - **data (-d)**: Must be valid JSON. Always wrap in single quotes to prevent shell expansion. |
| 50 | - **max-amount**: Must be a positive integer (`^\d+$`). |
| 51 | |
| 52 | Do not pass unvalidated user input into the command. |
| 53 | |
| 54 | ## Examples |
| 55 | |
| 56 | ```bash |
| 57 | # Make a GET request (auto-pays) |
| 58 | npx awal@2.0.3 x402 pay https://example.com/api/weather |
| 59 | |
| 60 | # Make a POST request with body |
| 61 | npx awal@2.0.3 x402 pay https://example.com/api/sentiment -X POST -d '{"text": "I love this product"}' |
| 62 | |
| 63 | # Limit max payment to $0.10 |
| 64 | npx awal@2.0.3 x402 pay https://example.com/api/data --max-amount 100000 |
| 65 | ``` |
| 66 | |
| 67 | ## Prerequisites |
| 68 | |
| 69 | - Must be authenticated (`npx awal@2.0.3 status` to check, see `authenticate-wallet` skill) |
| 70 | - Wallet must have sufficient USDC balance (`npx awal@2.0.3 balance` to check) |
| 71 | - If you don't know the endpoint URL, use the `search-for-service` skill to find services first |
| 72 | |
| 73 | ## Error Handling |
| 74 | |
| 75 | - "Not authenticated" - Run `awal auth login <email>` first, or see `authenticate-wallet` skill |
| 76 | - "No X402 payment requirements found" - URL may not be an x402 endpoint; use `search-for-service` to find valid endpoints |
| 77 | - "Insufficient balance" - Fund wallet with USDC; see `fund` skill |