import express from "express";
import { paymentMiddleware } from "x402-express";
const app = express();
app.use(paymentMiddleware(
"0xYourAddress",
{
"/premium-api": {
price: "$0.05",
network: "sei-testnet",
config: {
description: "Premium API access",
maxTimeoutSeconds: 120,
}
},
"/data-feed": {
price: "$0.01",
network: "sei-testnet",
config: {
description: "Real-time data feed",
mimeType: "application/json",
}
}
},
{
url: "https://x402.org/facilitator" // Use test facilitator
},
{
appName: "My Premium API",
appLogo: "https://example.com/logo.png"
}
));
app.get("/premium-api", (req, res) => {
res.json({
data: "This is premium content",
timestamp: new Date().toISOString()
});
});
app.get("/data-feed", (req, res) => {
res.json({
price: Math.random() * 100,
symbol: "BTC/USD",
timestamp: Date.now()
});
});
app.listen(3000, () => {
console.log("Server running on port 3000");
});