Skip to main content
The Express middleware adds x402 payment walls to individual routes or your entire application.

Route-level middleware

Apply the middleware to specific routes:

App-level middleware

Apply to all routes:

Multiple payment methods

Accept payments on different chains from the same endpoint:

Different prices per route

Create separate middleware instances for different routes:

Error handling

The middleware returns appropriate HTTP responses for payment errors:
  • 402 — No payment provided, returns requirements.
  • 400 — Malformed payment payload.
  • 402 — Payment verification or settlement failed, returns requirements again.
Errors from the facilitator are logged and translated into HTTP responses. Your route handler is only called after successful payment.

Further reading