x402 is a protocol for internet payments. When a client requests a paid resource, your server returns a 402 Payment Required response with payment details. The client completes the payment and retries the request with proof of payment.
Add payment middleware to your endpoint so it can accept x402 payments. The middleware handles payment verification and settlement with Stripe per request to /paid.
import { paymentMiddleware } from "@x402/hono";
import { x402ResourceServer, HTTPFacilitatorClient } from "@x402/core/server";
app.use(
paymentMiddleware(
{
"GET /paid": {
price: "$0.001",
network: "base-sepolia",
config: { description: "Access to paid content" }
}
},
facilitatorClient,
resourceServer
)
);
Make a request to your server without an existing payment header, and you receive a 402 response with payment requirements.
curl http://localhost:3000/paid
To run mainnet transactions, integrate with the mainnet facilitator and configure your environment for production use.