Skip to main content
Accept crypto payments in your Express API with a single middleware function.

Installation

Quick Start

This page covers Express v5+ with @armory-sh/middleware-express. For Express v4, use the separate package page: @armory-sh/middleware-express-v4.

How It Works

The middleware intercepts requests and:
  1. Checks for payment headers (X-Payment or X402-PAYMENT)
  2. Verifies the payment signature and amount
  3. Attaches payment info to req.payment
  4. Calls next() if valid, or returns 402 if invalid

Configuration

Payment Requirements

Common Token Addresses

Verification Options

See runtime verification configuration in your deployment environment and middleware setup.

Advanced Mix-and-Match Config (Current API)

You can mix and match network, token, facilitator, and amount by providing explicit requirements:
extensions are fail-open filtered per facilitator capability (/supported): unsupported keys are automatically omitted from the challenge header.

Accessing Payment Info

The middleware augments the Express request with payment information:
Available Properties:

Response Headers

On successful verification, the middleware adds:

Error Responses

402 Payment Required

No payment header was provided.

400 Invalid Payload

Payment header exists but couldn’t be decoded.

402 Verification Failed

Payment signature or amount was invalid.

Tips

Express middleware runs in order — place paymentMiddleware before any routes that require payment.