@ftptech/x402-canton-express
v0.1.0
Published
Express middleware to gate routes behind Canton x402 payment via a facilitator.
Maintainers
Readme
@ftptech/x402-canton-express
Express middleware that gates routes behind Canton x402 payment via a facilitator.
Install
npm i @ftptech/x402-canton-core @ftptech/x402-canton-expressNote: the
@ftpnpm scope is not final — it may change before the first public release (seedocs/PUBLISHING.md). Pin the version you install and check the README for the current package name.
Quick example
import express from "express";
import { cantonPaymentMiddleware } from "@ftptech/x402-canton-express";
const app = express();
app.use(express.json());
app.use(
cantonPaymentMiddleware({
routes: {
"GET /api/data": {
accepts: [paymentRequirements],
description: "Premium data feed",
},
},
facilitatorUrl: process.env.FACILITATOR_URL!,
})
);
app.get("/api/data", (_req, res) => res.json({ data: "premium" }));Per-request flow:
- No
PAYMENT-SIGNATURE→ 402 withPAYMENT-REQUIREDcarryingaccepts[]and the resource URL. - With signature → calls facilitator
/verify. If invalid → 402 with theinvalidReason. - If valid → calls facilitator
/settle(pre-handler). On success, attachesPAYMENT-RESPONSEand runs the handler.
Peer dependency
Express 4 or 5.
