start Command
The start command launches the x402test mock server for testing payment flows.
npx x402test start [options]What It Does
Section titled “What It Does”- Loads Configuration: Reads
x402test.config.js - Initializes Wallets: Loads or creates test wallets
- Starts Server: Launches HTTP server with configured routes
- Accepts Payments: Processes and verifies payment requests
Options
Section titled “Options”—config, -c
Section titled “—config, -c”Specify a custom configuration file.
npx x402test start --config ./custom.config.jsDefault: ./x402test.config.js
—port, -p
Section titled “—port, -p”Override the port from configuration.
npx x402test start --port 8080Default: Value from config file (default: 4402)
Output
Section titled “Output”--------------------------------------------------x402test v0.1.2Testing Solana x402 Payment Flows--------------------------------------------------
✔ Loaded config from ./x402test.config.js✔ Server started successfully
x402test Mock Server Started Port: 4402 Network: solana-devnet Recipient: FcxKSp7YxqYXdq...
Configured Routes: /api/premium Price: 0.10 USDC Description: Premium content access /api/data Price: 0.01 USDC Description: Data API access
Ready to accept payments at http://localhost:4402Default Behavior
Section titled “Default Behavior”If no config file is found:
npx x402test start✘ No config file found, using default configuration✘ Run "x402test init" to create a config file
✔ Server started successfully
x402test Mock Server Started Port: 4402 Network: solana-devnet Recipient: (temp wallet)
Configured Routes: /api/test Price: 0.01 USDC Description: Test endpoint
Ready to accept payments at http://localhost:4402Examples
Section titled “Examples”Basic Start
Section titled “Basic Start”npx x402test startCustom Port
Section titled “Custom Port”npx x402test start --port 8080Custom Config
Section titled “Custom Config”npx x402test start --config ./production.config.jsUsing Environment Variables
Section titled “Using Environment Variables”PORT=8080 npx x402test startServer Logs
Section titled “Server Logs”The server logs all requests and payments:
Successful Payment
Section titled “Successful Payment” GET /api/data X-PAYMENT header present Found token transfer (type 12) Source owner: FcxKSp7YxqYXdq... Destination owner: EPjFWdd5Aufq... Marked signature used: 5XzT4qW3... for /api/data with amount 10000✔ Payment verified✔ Response sent: 200Payment Required
Section titled “Payment Required” GET /api/premium✔ Payment required response sent: 402Failed Verification
Section titled “Failed Verification” GET /api/data X-PAYMENT header present✘ Payment verification failed: Insufficient amount✔ Payment required response sent: 402Stopping the Server
Section titled “Stopping the Server”Press Ctrl+C to stop the server:
^CServer stoppedBackground Mode
Section titled “Background Mode”Using nohup
Section titled “Using nohup”nohup npx x402test start > server.log 2>&1 &Using pm2
Section titled “Using pm2”npm install -g pm2
pm2 start "npx x402test start" --name x402test
pm2 logs x402test
pm2 stop x402testUsing screen
Section titled “Using screen”screen -S x402test
npx x402test start
screen -r x402testServer Configuration
Section titled “Server Configuration”The server uses settings from x402test.config.js:
export default { // Server port port: 4402,
// Solana network network: "solana-devnet",
// Solana RPC URL rpcUrl: "http://localhost:8899",
// Wallet to receive payments recipient: "FcxKSp7YxqYXdq...",
// Payment-protected endpoints routes: { "/api/endpoint": { price: "0.01", description: "Endpoint description", response: { data: "response" }, }, },};Error Handling
Section titled “Error Handling”Port Already in Use
Section titled “Port Already in Use”✘ Failed to start server: Port 4402 is already in useSolutions:
npx x402test start --port 8080
lsof -ti:4402 | xargs killConfig File Not Found
Section titled “Config File Not Found”✘ Failed to load config: Config file not foundSolution:
npx x402test initnpx x402test startInvalid Configuration
Section titled “Invalid Configuration”✘ Failed to load config: Invalid configuration formatSolution:
- Check config file syntax
- Ensure it exports a default object
- Validate all required fields
Wallet Not Found
Section titled “Wallet Not Found”✘ Failed to start server: Wallet not foundSolution:
npx x402test init --forcenpx x402test startRPC Connection Failed
Section titled “RPC Connection Failed”✘ Failed to connect to Solana RPCSolutions:
- Start Solana validator:
solana-test-validator - Check RPC URL in config
- Verify network connectivity
Health Check
Section titled “Health Check”Check if server is running:
curl http://localhost:4402/api/testShould return 402 Payment Required:
{ "x402Version": 1, "accepts": [{ "scheme": "solanaTransferChecked", "maxAmountRequired": "10000", ... }]}Production Deployment
Section titled “Production Deployment”Using Docker
Section titled “Using Docker”FROM node:18WORKDIR /appCOPY package*.json ./RUN npm installCOPY . .EXPOSE 4402CMD ["npx", "x402test", "start"]Using systemd
Section titled “Using systemd”[Unit]Description=x402test ServerAfter=network.target
[Service]Type=simpleUser=www-dataWorkingDirectory=/path/to/projectExecStart=/usr/bin/npx x402test startRestart=on-failure
[Install]WantedBy=multi-user.targetBest Practices
Section titled “Best Practices”- Local Validator: Use
solana-test-validatorfor development - Port Management: Use standard port (4402) or environment variable
- Log Rotation: Implement log rotation for production
- Monitoring: Monitor server health and payment processing
- Security: Never expose test wallets in production
Next Steps
Section titled “Next Steps”- routes Command - List configured routes
- Testing Client - Make payment requests
- Mock Server - Configure routes