Skip to main content
Add the official x402 middleware to your Express app and point it at x402Go. Requests to your paid routes then get a payment request, and your handler runs once the customer has paid. This guide shows the Express-specific setup. For credentials, choosing a token, and going live, see the Quickstart.

Install

Environment variables

Get your API key and payment address from the x402Go dashboard. Get the token values from GET /supported.

Add the middleware

Register the middleware before the routes it protects. Each key in the config ('GET /premium') is a route that requires payment, and you can give each route its own price.

Accept more than one token

List several entries in accepts. Each uses its own token’s asset, name, and version from /supported, and the customer’s app pays with whichever token it holds:
Set amount per token. Tokens can have different decimals, so the same number is not always the same price. Every price must also be higher than the x402Go fee for that token.

Test it

An unpaid request returns 402 Payment Required with the payment request in the response. To complete a payment, use an x402 client. The Celo Sepolia sandbox has a working example with test tokens.

Before you deploy

  • Keep FACILITATOR_API_KEY on the server only. Never expose it to browsers or commit it to source control.
  • Use the payment address you got from the dashboard as PAY_TO, not your payout wallet. Payments to any other address are rejected.
  • The server fails to start if a required variable is missing. This is intentional, so a misconfigured deployment doesn’t serve content for free or accept payments it can’t settle.