CLI for testing x402-enabled payment-gated APIs
x402-cli is an early-stage Go project in the AI payments / x402 ecosystem, focused on a2a, cli, eip-3009, x402. It currently has 2 GitHub stars and 0 forks, and sits alongside related tools like wispy, machi, internet-court-skill.
Test x402 payment-gated APIs from your terminal. No ETH or SOL needed for gas.
-y flag for automationbrew tap port402/tap
brew install x402-cli
go install github.com/port402/x402-cli/cmd/x402@latest
Download pre-built binaries from the releases page.
x402 health api.example.com/resource # https:// auto-prefixed
x402 health https://api.example.com/resource --agent # Also check for agent card
x402 agent https://api.example.com
x402 test https://api.example.com/resource --keystore ~/.foundry/keystores/my-wallet
x402 test https://api.example.com/resource --solana-keypair ~/.config/solana/id.json
x402 test https://api.example.com/resource --keystore ~/.foundry/keystores/my-wallet --dry-run
$ x402 health https://jupiter.api.corbits.dev/ultra/v1/order
✓ https://jupiter.api.corbits.dev/ultra/v1/order
Status: 402 Payment Required
Protocol: v1 (legacy)
Latency: 260ms
Payment: 0.01 USDC on Solana Mainnet
Checks:
✓ Endpoint reachable
✓ Returns 402
✓ Valid payment body
✓ Has payment options
✓ Has EVM option
✓ Has Solana option
✓ Known token
$ x402 health https://api.example.com/endpoint --agent
✓ https://api.example.com/endpoint
Status: 402 Payment Required
Protocol: v2 (current)
Latency: 120ms
Payment: 0.01 USDC on Base
Checks:
✓ Endpoint reachable
✓ Returns 402
✓ Valid payment header
✓ Has payment options
✓ Has EVM option
✓ Known token
Agent: Recipe Agent v1.0.0
Agent that helps with recipes
Provider: Example Inc (https://example.com)
Skills:
• recipe-search
Find recipes by ingredients or cuisine type
• meal-plan
Generate weekly meal plans based on preferences
Capabilities: streaming
$ x402 test https://x402-dotnet.azurewebsites.net/resource/middleware \
--keystore ~/.foundry/keystores/test --dry-run
✓ x402 endpoint detected (v2)
Payment Requirements:
Network: Base Sepolia (eip155:84532)
Token: USDC (0x036c...cf7e)
Amount: 0.001000 USDC
Recipient: 0xB889...64fc
⚠ Dry run mode - no payment will be made
$ x402 test https://x402-dotnet.azurewebsites.net/resource/middleware \
--keystore ~/.foundry/keystores/test
✓ x402 endpoint detected (v2)
Payment Requirements:
Network: Base Sepolia (eip155:84532)
Token: USDC (0x036c...cf7e)
Amount: 0.001000 USDC
Recipient: 0xB889...64fc
? Proceed with payment? [y/N] y
• Loading wallet...
• Signing payment authorization...
• Sending payment...
✓ Payment successful!
Transaction: 0xb945a8c...
Explorer: https://sepolia.basescan.org/tx/0xb945a8c...
Response (200 OK):
{
"message": "Access granted",
"timestamp": "2026-01-12T10:30:00Z"
}
$ x402 agent https://api.example.com
✓ Agent card found (/.well-known/agent.json)
Agent:
Name: Recipe Agent
Version: 1.0.0
Description: Agent that helps with recipes
Skills:
• recipe-search — Find recipes by ingredients
• meal-plan — Generate weekly meal plans
Docs: https://docs.example.com/agent
$ x402 agent https://example.com
⚠ No agent card found
Tried:
• /.well-known/agent.json (404)
• /.well-known/agent-card.json (404)
• /.well-known/agents.json (404)
Hint: Use --card-url to specify a custom location
x402 health <url>Check if an endpoint is x402-enabled and validate its payment requirements.
x402 health https://api.example.com/endpoint
x402 health https://api.example.com/endpoint --json # JSON output
x402 health https://api.example.com/endpoint --method POST # POST-only APIs
x402 health https://api.example.com/endpoint --agent # Also discover agent card
| Flag | Description |
|---|---|
--agent |
Also discover A2A agent card from the endpoint |
--method |
HTTP method (default: GET) |
--timeout |
Request timeout in seconds (default: 30) |
x402 agent <url>Discover A2A (Agent-to-Agent) protocol agent cards from endpoints.
x402 agent https://api.example.com # Auto-discover
x402 agent https://api.example.com --json # JSON output
x402 agent https://api.example.com --card-url /custom/agent.json # Custom path
| Flag | Description |
|---|---|
--card-url |
Custom agent card path (overrides discovery) |
--timeout |
Request timeout in seconds (default: 5) |
Discovery paths (tried in order):
/.well-known/agent.json (A2A v0.1)/.well-known/agent-card.json (A2A v0.2+)/.well-known/agents.json (Wildcard spec)x402 test <url>Make a test payment to an x402 endpoint.
# EVM payments (Base, Ethereum, etc.)
x402 test <url> --keystore <path> # Interactive mode
x402 test <url> --keystore <path> --dry-run # Preview only
x402 test <url> --keystore <path> --max-amount 0.05 # Safety cap
# Solana payments
x402 test <url> --solana-keypair ~/.config/solana/id.json
| Flag | Description |
|---|---|
--keystore |
Path to EVM Web3 keystore file |
--wallet |
Hex-encoded EVM private key (or PRIVATE_KEY env) |
--solana-keypair |
Path to Solana keypair file (JSON array or Base58) |
--solana-rpc |
Custom Solana RPC endpoint URL |
--dry-run |
Show payment details without executing |
-y, --no-confirm |
Skip payment confirmation prompt |
--skip-payment-confirmation |
Skip payment confirmation prompt (alias) |
--max-amount |
Maximum payment amount (safety cap) |
--method |
HTTP method (GET, POST, PUT) |
--header |
Custom HTTP header (repeatable) |
--data |
Request body for POST/PUT |
--timeout |
Request timeout in seconds |
Chain Selection:
--solana-keypair is provided and endpoint supports Solana, Solana is preferredx402 batch-health <file>Check multiple endpoints from a JSON file.
x402 batch-health urls.json
x402 batch-health urls.json --parallel 5 # Parallel execution
x402 batch-health urls.json --fail-fast # Stop on first failure
Input formats:
["https://api1.example.com", "https://api2.example.com"]
[{"url": "https://api.example.com", "method": "POST"}]
x402 networksList all supported blockchain networks with their CAIP-2 identifiers, tokens, and explorers.
x402 networks # Table output
x402 networks --json # JSON output
x402 completionGenerate shell completion scripts for tab-completion support.
x402 completion bash # Bash
x402 completion zsh # Zsh
x402 completion fish # Fish
x402 completion powershell # PowerShell
# Example: enable for current bash session
source <(x402 completion bash)
# Example: persist for zsh
x402 completion zsh > "${fpath[1]}/_x402"
x402 versionx402 version
x402 version --json
--keystore ~/.foundry/keystores/my-wallet--wallet 0xac0974...PRIVATE_KEY=0xac0974... environment variableecho "0xac0974..." | x402 test ...--solana-keypair ~/.config/solana/id.json (JSON array format)--solana-keypair ~/.config/solana/id.json (Base58 string format)Supported keypair formats:
[1,2,3,...64 bytes...] (Solana CLI format)Run x402 networks to see all supported networks with their tokens and explorers.
| Network | Chain ID |
|---|---|
| Ethereum | eip155:1 |
| Base | eip155:8453 |
| Base Sepolia | eip155:84532 |
| Polygon | eip155:137 |
| Arbitrum One | eip155:42161 |
| Optimism | eip155:10 |
| Network | CAIP-2 Identifier |
|---|---|
| Solana Mainnet | solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp |
| Solana Devnet | solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1 |
| Solana Testnet | solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z |
USDC on all supported networks (EVM and Solana).
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General failure |
| 2 | Input validation error |
| 3 | Network error |
| 4 | Protocol error |
| 5 | Payment rejected |
# Health check with JSON parsing
x402 health https://api.example.com/endpoint --json | jq '.exitCode'
# Dry-run in CI (use -y to skip confirmation)
x402 test https://api.example.com/endpoint \
--keystore ./test-wallet.json \
--dry-run -y
#!/bin/bash
for url in "https://api1.example.com" "https://api2.example.com"; do
x402 test "$url" \
--keystore ~/.foundry/keystores/test \
--max-amount 0.01 -y
done
The x402 protocol enables payment-gated APIs using HTTP 402 responses with gasless token transfers:
┌─────────┐ ┌─────────┐ ┌─────────────┐
│ Client │ │ Server │ │ Facilitator │
└────┬────┘ └────┬────┘ └──────┬──────┘
│ │ │
│ 1. GET /resource │ │
│ ───────────────────────────> │ │
│ │ │
│ 2. 402 Payment Required │ │
│ + payment requirements │ │
│ <─────────────────────────── │ │
│ │ │
│ 3. Sign EIP-3009 auth │ │
│ (gasless, off-chain) │ │
│ │ │
│ 4. GET /resource │ │
│ + X-PAYMENT header │ │
│ ───────────────────────────> │ │
│ │ │
│ │ 5. Verify & settle payment │
│ │ ──────────────────────────────>│
│ │ │
│ │ 6. Payment confirmed │
│ │ <──────────────────────────────│
│ │ │
│ 7. 200 OK + resource │ │
│ <─────────────────────────── │ │
│ │ │
| Term | Description |
|---|---|
| HTTP 402 | Status code indicating payment is required |
| EIP-3009 | Gasless token transfer standard (no ETH needed) |
| Facilitator | Service that verifies and settles payments on-chain |
| X-PAYMENT | Header containing the signed payment authorization |
The test command requires a wallet. Choose based on your target network:
# Install Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup
# Create a new keystore
cast wallet new ~/.foundry/keystores/
# Or import existing key
cast wallet import my-wallet --interactive
geth account new --keystore ~/.keystores/
# Install Solana CLI
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
# Create a new keypair
solana-keygen new --outfile ~/.config/solana/id.json
# View your address
solana address
The CLI supports two formats:
[1,2,3,...64 bytes...] (default Solana CLI format)Security: Never share your keystore, keypair, or password. Use dedicated wallets with only test funds.
git clone https://github.com/port402/x402-cli.git
cd x402-cli
make build
| Target | Description |
|---|---|
make build |
Build the binary |
make test |
Run tests |
make lint |
Run linter |
make check |
Run all checks |
make help |
Show all targets |
Contributions welcome! See CONTRIBUTING.md for guidelines.
Report vulnerabilities via SECURITY.md. Do not open public issues for security concerns.
MIT — see LICENSE
Autonomous AI Agent Platform - Marathon Mode, x402 Payments, ERC-8004 Identity, A2A Protocol. Powered by Gemini.
Agent behavior that compiles
The trust layer for agent-to-agent commerce — natural-language mandates, ERC-7710 delegated permissions, x402 payments, escrow, and dispute resolution as one open, catch-all Agent Skill / Claude Code plugin.
Your AI trading terminal assistant for US stocks, commodities, forex, and crypto.
Golang SDK for A2A Protocol
Publishes localhost services to the agentic web through self-hostable, trustless relays with x402 payments.
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Go implementation of the x402 payment protocol