CLI Overview
x402test provides a command-line interface for managing your test environment.
Installation
Section titled “Installation”The CLI is included when you install x402test:
pnpm add -D x402testAvailable Commands
Section titled “Available Commands”| Command | Description |
|---|---|
init | Initialize configuration and create test wallet |
start | Start the mock server |
routes | List configured routes |
Basic Usage
Section titled “Basic Usage”npx x402test init
npx x402test start
npx x402test routesCommand Structure
Section titled “Command Structure”x402test <command> [options]Global Options
Section titled “Global Options”Version
Section titled “Version”x402test --versionx402test -vx402test --help
x402test init --helpx402test start --helpx402test routes --helpnpx vs Local
Section titled “npx vs Local”Using npx (Recommended)
Section titled “Using npx (Recommended)”npx x402test startAdvantages:
- Always uses latest version
- No global installation needed
- Works in any project
Local Installation
Section titled “Local Installation”npm install -g x402test
x402test startConfiguration File
Section titled “Configuration File”Most commands look for x402test.config.js by default:
export default { port: 4402, network: "solana-devnet", rpcUrl: "http://localhost:8899", recipient: "YOUR_WALLET_ADDRESS", routes: { // ... routes },};You can specify a custom config file with --config:
npx x402test start --config ./custom.config.jsQuick Reference
Section titled “Quick Reference”Initialize Project
Section titled “Initialize Project”npx x402test initCreates:
x402test.config.js- Configuration.x402test-wallets.json- Test wallets
Start Development Server
Section titled “Start Development Server”npx x402test startStarts mock server at http://localhost:4402
Custom Port
Section titled “Custom Port”npx x402test start --port 8080List Routes
Section titled “List Routes”npx x402test routesShows all configured payment-protected endpoints
Environment Variables
Section titled “Environment Variables”You can use environment variables in your config:
export default { port: parseInt(process.env.PORT || "4402"), rpcUrl: process.env.RPC_URL || "http://localhost:8899", recipient: process.env.RECIPIENT_WALLET, routes: { // ... routes },};Usage:
PORT=8080 npx x402test startExit Codes
Section titled “Exit Codes”| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Error occurred |
Troubleshooting
Section titled “Troubleshooting”Command Not Found
Section titled “Command Not Found”pnpm add -D x402test
npx x402test --versionPermission Denied
Section titled “Permission Denied”sudo x402test start
npx x402test startConfig File Not Found
Section titled “Config File Not Found”npx x402test init
npx x402test start --config ./my-config.jsPort Already in Use
Section titled “Port Already in Use”npx x402test start --port 8080
lsof -ti:4402 | xargs killNext Steps
Section titled “Next Steps”- init Command - Initialize configuration
- start Command - Start mock server
- routes Command - List routes