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

Installation

Quick Start


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. Stores payment info in the Hono context
  4. Calls next() if valid, or returns 402 if invalid

Configuration

Minimal Setup

All Options


Accessing Payment Info

Payment information is stored in the Hono context:
Available Properties:

Response Headers

On successful verification:

Error Responses

402 Payment Required

402 Verification Failed


Multi-Network Support

Accept payments across multiple networks and tokens:

Advanced Mix-and-Match Config (Current API)

If you need fully custom amount-per-requirement combinations, use explicit requirements:
Extension keys are fail-open filtered by facilitator capability: unsupported keys are automatically omitted from PAYMENT-REQUIRED.

Tips

The amount parameter accepts human-readable strings like "1.0" for 1 token, or use bigint for precise decimal control.
Hono middleware applies to routes that match the path pattern. Use /api/* to protect all API routes, or specific paths like /premium/* for paid content.
The middleware will return 402 before your handler runs if payment is missing or invalid. Only verified requests reach your route handlers.