@chainpeavax/cli
v2.0.1
Published
ChainPe Provider CLI — Monetize any API with x402 micropayments on Avalanche C-Chain
Maintainers
Readme
@chainpe/cli
Monetize any API with x402 micropayments on Avalanche
ChainPe is a reverse proxy that sits in front of your HTTP API and enforces x402 protocol payments on every request. One command, zero backend changes, real AVAX/USDC settlements on Avalanche.
Installation
npm install -g @chainpe/cliQuick Start
1. Initialize Configuration
chainpe initThis interactive wizard will ask you for:
- Your API URL (the backend to monetize)
- Service name and description
- Price per request
- Payment token (USDC)
- Your Avalanche wallet address (to receive payments)
- Optional: private key for on-chain registration
Note: The provider CLI only needs your wallet address to receive payments. The private key is only required if you want to register your service on-chain during setup. You can also skip registration and do it manually later.
2. Start the Proxy
chainpe startYour API is now monetized! Every request to http://localhost:4402/* requires a micropayment.
3. Register Your Service (Optional)
Make your service discoverable by AI agents with on-chain registration. You have 3 options:
Option 1: QR Code with Core Wallet Mobile (Recommended) 📱
chainpe init
# Select "Scan QR code with Core Wallet mobile app"- A QR code will appear in your terminal
- Open Core Wallet on your phone
- Tap the WalletConnect icon (top right)
- Scan the QR code
- Approve the transaction (~1.5 USDC fee)
- Done! Your service is registered on-chain
Option 2: Private key Phrase 🔑
chainpe init
# Select "Paste private key phrase"Paste your private key (0x…) to sign the transaction directly.
Getting your private key from Core Wallet:
- Open Core Wallet mobile app
- Go to Settings → Account Settings
- Select your account → Show Passphrase
- Copy all a 0x private key in order
Option 3: Manual Registration Later ⏭️
Skip registration during init and do it later:
chainpe registerCommands
| Command | Description |
|---------|-------------|
| chainpe init | Interactive setup wizard |
| chainpe start | Start the x402 payment proxy |
| chainpe register | Register service on Avalanche |
| chainpe list | List registered services |
| chainpe status | Show current config and wallet balance |
How It Works
Client Request → ChainPe Proxy → 402 Payment Required
↓
Client Signs Payment → Proxy Verifies → Forwards to Your API
↓
Response + Settlement- Client makes request to proxy
- Proxy returns 402 with payment instructions
- Client signs x402 payment authorization
- Proxy verifies signature, forwards request to your API
- Response sent to client, payment settled on Avalanche
Programmatic Usage
import { startProxyServer } from "@chainpe/cli";
const handle = await startProxyServer({
config: {
targetUrl: "http://localhost:3000",
pricePerRequest: "0.01",
paymentToken: "AVAX",
walletAddress: "YOUR_ADDRESS",
proxyPort: 4402,
network: "avalanche",
}
});
console.log(`Proxy running at ${handle.url}`);Requirements
- Node.js >= 18
- Avalanche wallet with AVAX for gas
License
MIT
