Skip to content

start Command

The start command launches the x402test mock server for testing payment flows.

Terminal window
npx x402test start [options]
  1. Loads Configuration: Reads x402test.config.js
  2. Initializes Wallets: Loads or creates test wallets
  3. Starts Server: Launches HTTP server with configured routes
  4. Accepts Payments: Processes and verifies payment requests

Specify a custom configuration file.

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

Default: ./x402test.config.js

Override the port from configuration.

Terminal window
npx x402test start --port 8080

Default: Value from config file (default: 4402)

--------------------------------------------------
x402test v0.1.2
Testing 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:4402

If no config file is found:

Terminal window
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:4402
Terminal window
npx x402test start
Terminal window
npx x402test start --port 8080
Terminal window
npx x402test start --config ./production.config.js
Terminal window
PORT=8080 npx x402test start

The server logs all requests and payments:

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: 200
GET /api/premium
✔ Payment required response sent: 402
GET /api/data
X-PAYMENT header present
✘ Payment verification failed: Insufficient amount
✔ Payment required response sent: 402

Press Ctrl+C to stop the server:

^C
Server stopped
Terminal window
nohup npx x402test start > server.log 2>&1 &
Terminal window
npm install -g pm2
pm2 start "npx x402test start" --name x402test
pm2 logs x402test
pm2 stop x402test
Terminal window
screen -S x402test
npx x402test start
screen -r x402test

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" },
},
},
};
✘ Failed to start server: Port 4402 is already in use

Solutions:

Terminal window
npx x402test start --port 8080
lsof -ti:4402 | xargs kill
✘ Failed to load config: Config file not found

Solution:

Terminal window
npx x402test init
npx x402test start
✘ Failed to load config: Invalid configuration format

Solution:

  1. Check config file syntax
  2. Ensure it exports a default object
  3. Validate all required fields
✘ Failed to start server: Wallet not found

Solution:

Terminal window
npx x402test init --force
npx x402test start
✘ Failed to connect to Solana RPC

Solutions:

  1. Start Solana validator: solana-test-validator
  2. Check RPC URL in config
  3. Verify network connectivity

Check if server is running:

Terminal window
curl http://localhost:4402/api/test

Should return 402 Payment Required:

{
"x402Version": 1,
"accepts": [{
"scheme": "solanaTransferChecked",
"maxAmountRequired": "10000",
...
}]
}
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 4402
CMD ["npx", "x402test", "start"]
[Unit]
Description=x402test Server
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/path/to/project
ExecStart=/usr/bin/npx x402test start
Restart=on-failure
[Install]
WantedBy=multi-user.target
  1. Local Validator: Use solana-test-validator for development
  2. Port Management: Use standard port (4402) or environment variable
  3. Log Rotation: Implement log rotation for production
  4. Monitoring: Monitor server health and payment processing
  5. Security: Never expose test wallets in production