x402-pay calls an x402-protected URL on behalf of the smart wallet. When the server returns 402 Payment Required, the CLI signs the payment using the wallet’s session, retries the request, and returns the response body. There is no --broadcast flag, payment and the request are one operation, so settlement happens as part of the call.
Use this command to test that a seller’s x402 integration is live, to consume paid APIs from scripts, or to demonstrate agent-buyer flows interactively.
How it works
There is no separate verify-then-execute step. The CLI receives the 402, signs against the wallet’s session, retries, and prints the response body plus the settlement receipt in one call.Prerequisites
Before callingx402-pay, confirm three things:
- Wallet exists.
polygon-agent wallet list. If missing, runpolygon-agent wallet create. - USDC balance.
polygon-agent balances --chain polygon. The wallet needs enough USDC to cover the price plus gas (keep ~0.1 USDC reserve). - The endpoint actually requires x402. Curl the URL once; if it returns 200 without a payment header, x402 isn’t gating it.
Command
| Flag | Default | Purpose |
|---|---|---|
--wallet | main | Wallet name |
--chain | none | Chain to pay on (defaults to wallet’s chain) |
--url | required | Endpoint URL |
--method | GET | HTTP method |
--body | none | Request body (JSON string) |
--header | none | Additional header Key:Value, repeatable |
--broadcast flag. x402-pay always settles as part of the call; running the command transfers USDC.
Worked example
Implementation
x402 Introduction
Protocol overview and facilitator list.
x402 Quickstart for Buyers
Programmatic buyer integration without the CLI.
x402 How It Works
Protocol mechanics, accepts block, receipts.
Balances and funding
Confirm USDC balance before calling.