x402wrap
v0.3.3
Published
Monetize any API endpoint with stablecoin micropayments via the x402 protocol
Maintainers
Readme
x402wrap
Monetize any API endpoint with stablecoin micropayments via the x402 protocol. Built on the official x402 SDK.
Install
npm install x402wrap expressQuick Start
import express from "express";
import { x402 } from "x402wrap";
const app = express();
// Add x402 payment middleware
app.use(x402({
walletAddress: "0xYourWalletAddress",
network: "base-sepolia",
routes: {
"GET /api/weather/:city": { price: "$0.001", description: "Weather data" },
"GET /api/joke": { price: "$0.0005", description: "Random joke" },
},
}));
// Your endpoints — only run after payment is verified
app.get("/api/weather/:city", (req, res) => {
res.json({ temp: 72, city: req.params.city });
});
app.get("/api/joke", (req, res) => {
res.json({ setup: "Why?", punchline: "Because." });
});
app.listen(3000);Per-Route Middleware
import { x402pay } from "x402wrap";
const pay = x402pay({
walletAddress: "0xYourWalletAddress",
network: "base-sepolia",
});
app.get("/api/data", pay("$0.01"), (req, res) => {
res.json({ data: "premium" });
});Configuration
| Option | Required | Default | Description |
|--------|----------|---------|-------------|
| walletAddress | Yes | — | Your wallet address (receives USDC payments) |
| network | No | base-sepolia | Currently only "base-sepolia" (testnet). Mainnet coming soon. |
| facilitatorUrl | No | Auto-detected | Override the x402 facilitator URL |
| apiKey | No | — | x402Wrap dashboard API key (for usage tracking) |
| dashboardUrl | No | https://x402wrap.draftlabs.org | Dashboard URL |
Network
| Network | Chain | Facilitator | Notes |
|---------|-------|-------------|-------|
| base-sepolia | Base Sepolia testnet | x402.org/facilitator (free) | Currently available |
Base mainnet support coming soon with Pro plan.
How It Works
- Client calls your API → gets
402 Payment Required - Client signs USDC payment authorization (via x402 SDK)
- Client retries with
PAYMENT-SIGNATUREheader - Middleware verifies + settles via Coinbase facilitator
- Your handler runs, returns data
Free Plan Limits
- 100 monetized calls / month
- 2 endpoints
- Base Sepolia testnet only
Dashboard
Sign up at x402wrap.draftlabs.org to track revenue, manage endpoints, and upgrade plans.
License
MIT
