Prerequisites
Ensure you have Node.js and npm installed on your machine and a funded wallet with USDC on Base Sepolia testnet.- Install Node.js (npm comes with Node.js)
- A wallet address with USDC tokens on Base Sepolia testnet
- Get test USDC from the Circle Faucet (select Base Sepolia)
Step 1: Create a New Project
Initialize a new project using the official Hono template:nodejs template when prompted. Then navigate to your project:
Step 2: Configure Your Receiving Address
Create a.env file with your wallet address:
Step 3: Create Your Paid API
Replace the contents ofsrc/index.ts with a simple string reversal service:
Step 4: Start the Server
The Hono template creates a ready-to-run server. Start your server:Step 5: Test Your Paid API
Test the free endpoints first:How It Works
x402-hono integrates x402 payment functionality directly into Hono applications:- Middleware Integration: Each route gets individual payment middleware
- USD Pricing: Prices are specified in USD (converted to appropriate token amounts)
- Service Discovery: Services with
discoverable: trueappear in x402 directories - Base Sepolia Testnet: Optimized for testing on Base Sepolia with USDC
Key Features
- Individual Route Protection: Middleware applied per route, not globally
- Automatic Discovery: Services appear in x402 service directories
- USD-Based Pricing: Human-readable pricing in dollars
- Testnet Ready: Designed for Base Sepolia testnet deployment
Configuration Options
Middleware Parameters
Route Configuration
Each route specifies pricing and network:Error Handling
Common issues and solutions:-
“RECEIVING_ADDRESS not configured”
- Ensure your
.envfile contains the RECEIVING_ADDRESS variable - Restart your server after adding the environment variable
- Ensure your
-
“Facilitator connection failed”
- Verify the facilitator URL is accessible (
x402.org/facilitator) - Check your internet connection
- Verify the facilitator URL is accessible (
-
“Payment validation failed”
- Ensure your receiving address has sufficient USDC balance on Base Sepolia
- Verify the address format is correct
-
“Invalid string parameter”
- Ensure you’re sending a JSON object with a “str” field
- The str field must be a string value
Testnet Deployment
For Base Sepolia testnet deployment:-
Environment Setup:
-
Token Setup:
- Get test USDC from Circle Faucet (select Base Sepolia)
- The x402.org facilitator handles payment processing
- Testing: Use the x402.org public testnet facilitator for development
Next Steps
Once your Base Sepolia x402-hono service is running:- Buy from your own services using the Faremeter client SDK
- Run your own facilitator for payment processing
- Create SKALE services using Faremeter middleware
- Contract Dirt Road Dev for support, questions, or to request a quote for work