Skip to content

init Command

The init command creates a configuration file and test wallet for your project.

Terminal window
npx x402test init [options]
  1. Creates Configuration File: Generates x402test.config.js
  2. Creates Test Wallet: Generates and funds a test wallet
  3. Saves Wallet: Stores wallet in .x402test-wallets.json

Overwrite existing configuration file.

Terminal window
npx x402test init --force

Use Case: Recreate configuration after accidental modification

✔ Initializing x402test configuration...
✔ Creating new x402test config...
✔ Creating test wallet...
✔ Config file created at x402test.config.js
✔ Recipient wallet: FcxKSp7YxqYXdq...
✔ USDC balance: 1000 USDC
✔ Ready to start your server! Run 'x402test start' to start the server.
// x402test configuration
export default {
port: 4402,
network: "solana-devnet",
rpcUrl: "http://localhost:8899",
recipient: "FcxKSp7YxqYXdq...",
routes: {
"/api/premium": {
price: "0.10",
description: "Premium content access",
response: {
data: "This is premium content!",
timestamp: Date.now(),
},
},
"/api/data": {
price: "0.01",
description: "Data API access",
response: (req) => ({
method: req.method,
path: req.path,
data: { message: "Your data here" },
}),
},
},
};
{
"wallets": [{
"publicKey": "FcxKSp7YxqYXdq...",
"secretKey": [...],
"tokenAccounts": {
"USDC": "EPjFWdd5AufqSSqeM2..."
}
}],
"mints": {
"USDC": "EPjFWdd5AufqSSqeM2..."
}
}

Important: Add to .gitignore!

.x402test-wallets.json
Terminal window
npx x402test init
Terminal window
npx x402test init --force

Use when you want to:

  • Reset configuration to defaults
  • Fix corrupted config file
  • Start fresh after experiments

After running init, edit x402test.config.js:

export default {
port: 8080, // Change from 4402
// ... rest of config
};
export default {
// ... existing config
routes: {
"/api/premium": {
price: "0.10",
description: "Premium content",
response: { data: "Premium content" },
},
"/api/basic": {
price: "0.01",
description: "Basic content",
response: { data: "Basic content" },
},
// Add your routes here
"/api/custom": {
price: "0.05",
description: "Custom endpoint",
response: { custom: true },
},
},
};
export default {
port: parseInt(process.env.PORT || "4402"),
rpcUrl: process.env.RPC_URL || "http://localhost:8899",
recipient: process.env.RECIPIENT_WALLET || "default-wallet",
// ... rest of config
};
✘ Config file already exists. Use --force to overwrite.

Solution:

Terminal window
npx x402test init --force
✘ Failed to create wallet: Connection failed

Solutions:

  1. Check Solana validator is running
  2. Verify RPC URL is correct
  3. Check network connectivity
✘ EACCES: permission denied

Solutions:

  1. Check file permissions
  2. Run in different directory
  3. Use sudo (not recommended)
  1. Version Control: Commit x402test.config.js, not .x402test-wallets.json
  2. Security: Never share or commit wallet files
  3. Team Setup: Each developer runs init independently
  4. CI/CD: Run init in CI pipeline for testing

Add these to .gitignore:

.x402test-wallets.json
.x402test-signatures.json

After running init:

  1. Review Config: Check x402test.config.js settings
  2. Start Server: Run npx x402test start
  3. Make Request: Test with x402 client
  4. Customize: Add your own routes and responses

If something goes wrong:

Terminal window
rm x402test.config.js
rm .x402test-wallets.json
rm .x402test-signatures.json
npx x402test init
Terminal window
rm .x402test-wallets.json
npx x402test init

The new wallet will have 1000 USDC again.