Skip to content

CLI Overview

x402test provides a command-line interface for managing your test environment.

The CLI is included when you install x402test:

Terminal window
pnpm add -D x402test
CommandDescription
initInitialize configuration and create test wallet
startStart the mock server
routesList configured routes
Terminal window
npx x402test init
npx x402test start
npx x402test routes
Terminal window
x402test <command> [options]
Terminal window
x402test --version
x402test -v
Terminal window
x402test --help
x402test init --help
x402test start --help
x402test routes --help
Terminal window
npx x402test start

Advantages:

  • Always uses latest version
  • No global installation needed
  • Works in any project
Terminal window
npm install -g x402test
x402test start

Most commands look for x402test.config.js by default:

x402test.config.js
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:

Terminal window
npx x402test start --config ./custom.config.js
Terminal window
npx x402test init

Creates:

  • x402test.config.js - Configuration
  • .x402test-wallets.json - Test wallets
Terminal window
npx x402test start

Starts mock server at http://localhost:4402

Terminal window
npx x402test start --port 8080
Terminal window
npx x402test routes

Shows all configured payment-protected endpoints

You can use environment variables in your config:

x402test.config.js
export default {
port: parseInt(process.env.PORT || "4402"),
rpcUrl: process.env.RPC_URL || "http://localhost:8899",
recipient: process.env.RECIPIENT_WALLET,
routes: {
// ... routes
},
};

Usage:

Terminal window
PORT=8080 npx x402test start
CodeMeaning
0Success
1Error occurred
Terminal window
pnpm add -D x402test
npx x402test --version
Terminal window
sudo x402test start
npx x402test start
Terminal window
npx x402test init
npx x402test start --config ./my-config.js
Terminal window
npx x402test start --port 8080
lsof -ti:4402 | xargs kill