Installation
This guide will walk you through installing x402test and setting up your development environment.
Prerequisites
Section titled “Prerequisites”Before installing x402test, make sure you have:
- Node.js: Version 18 or higher
- pnpm, npm, or yarn: Package manager
- Solana CLI (optional): For running a local validator
Install x402test
Section titled “Install x402test”Add x402test to your project as a development dependency:
pnpm add -D x402test
npm install --save-dev x402test
yarn add -D x402testInitialize Configuration
Section titled “Initialize Configuration”Run the initialization command to create a configuration file and test wallet:
npx x402test initThis will:
- Create a
x402test.config.jsconfiguration file - Generate a test wallet with auto-funded USDC
- Save wallet information to
.x402test-wallets.json
Configuration File
Section titled “Configuration File”The generated configuration file looks like this:
export default { port: 4402, network: "solana-devnet", rpcUrl: "http://localhost:8899",
recipient: "YOUR_WALLET_ADDRESS",
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" }, }), }, },};Set Up Local Solana Validator
Section titled “Set Up Local Solana Validator”For local testing, you’ll need a Solana test validator:
Install Solana CLI
Section titled “Install Solana CLI”sh -c "$(curl -sSfL https://release.solana.com/stable/install)"Start Test Validator
Section titled “Start Test Validator”solana-test-validatorThe validator should run on http://localhost:8899 by default.
Verify Installation
Section titled “Verify Installation”Check that the validator is running:
solana cluster-version --url http://localhost:8899Verify x402test Installation
Section titled “Verify x402test Installation”Test your installation by starting the mock server:
npx x402test startYou should see output like:
✔ x402test Mock Server Started Port: 4402 Network: solana-devnet Recipient: YOUR_WALLET_ADDRESS
✔ 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:4402Project Structure
Section titled “Project Structure”After initialization, your project should have:
your-project/├── x402test.config.js # Configuration file├── .x402test-wallets.json # Test wallets (auto-generated)├── .x402test-signatures.json # Used signatures (auto-generated)└── package.jsonGit Ignore
Section titled “Git Ignore”Add these files to your .gitignore:
.x402test-wallets.json.x402test-signatures.jsonx402test.config.js # Optional: commit if you want to share configNext Steps
Section titled “Next Steps”Now that you have x402test installed:
- Quick Start Guide - Make your first payment request
- How x402 Works - Understand the payment flow
- CLI Reference - Learn all CLI commands