Skip to main content
@x402r/cli makes a single x402 payment from the command line. You point it at an address, provide a signer, and get back the response body plus a settlement transaction hash. The CLI carries zero provider SDK dependencies. Raw private keys, JSON-RPC signers (Privy, Turnkey, Fireblocks, Safe), and custom signer modules all work through the same interface.

Install

No project install required. Pin the version (for example, @x402r/cli@0.2.0) for reproducible scripted workflows.

Usage

If the endpoint does not return HTTP 402, the CLI short-circuits and prints the response body with exit code 0. The CLI sends no payment.

Signer configuration

Configure exactly one signer source. CLI flags take precedence over environment variables. If the CLI finds zero or more than one source, it exits with code 6. Environment variable names use no X402R_ prefix to match Foundry, Hardhat, and x402-reference conventions.

Request options

Supported chains

The CLI reads the chain from the 402 response’s accepts[].network field. Any EVM chain known to viem/chains works, including Base and Base Sepolia. For chain IDs viem/chains does not recognize, pass --rpc <url> with an RPC endpoint.

Exit codes

Examples

Raw private key

JSON-RPC signer

Any endpoint that speaks eth_signTypedData_v4 works: Privy wallet RPC, Turnkey, Fireblocks, Safe, a local cast wallet endpoint, or a hardware wallet behind an RPC bridge.

Custom module (Privy)

privy-signer.js

Custom module (Coinbase CDP)

cdp-signer.js

JSON output

With --json, the CLI writes a single JSON envelope to stdout:
The CLI drops the signer field when the endpoint returned a non-402 response (the CLI sent no payment).

Signer module contract

A custom signer module must default-export a factory function with the signature () => Promise<Account>. The returned object must be a viem Account with at least address and signTypedData. The CLI only needs typed-data signatures; the facilitator broadcasts the transaction.

Programmatic usage

You can also use the pay function and resolveSigner directly from TypeScript:
The programmatic API uses the same PayFlags interface as the CLI binary. All options (chain, rpc, maxAmount, signer flags) are available.

Exports

The @x402r/cli package exports:

Next steps

Merchant guide

Accept payments and manage escrow releases.

Examples

Runnable examples for every SDK operation.