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

Install

Install matching versions of the @x402/* packages. If you see type errors, check the SDK’s installation guide for the versions it expects.

Environment variables

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

Add the middleware

Create server.ts:
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. This example runs on Node. On another runtime such as Bun or Cloudflare Workers, replace the serve call with export default app and read your variables from that runtime’s environment.

Accept more than one token

Add more entries to accepts, one per token. Each token needs its own asset, name, and version from /supported. See Express for an example. The same code works in Hono.

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 your payment address 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.