Skip to main content
Accept crypto payments in your Elysia API with a single middleware plugin.

Installation

Quick Start


How It Works

The middleware plugin:
  1. Checks for payment headers (X-Payment or X402-PAYMENT)
  2. Verifies the payment signature and amount
  3. Stores payment info in the Elysia store
  4. Proceeds to your handler if valid, or returns 402 if invalid

Configuration

Payment Requirements

Verification Options

Provide your verification backend configuration in middleware options for production deployments.

Advanced Mix-and-Match Config (Current API)

For full custom amount-per-combination control, use explicit requirements:
extensions are fail-open filtered based on facilitator capability; unsupported keys are omitted from challenge headers automatically.

Accessing Payment Info

Payment information is stored in the Elysia store:
Available Properties:

Type Safety

For full TypeScript support, type your Elysia instance:

Response Headers

On successful verification:

Error Responses

402 Payment Required

No payment header was provided.

400 Invalid Payload

Payment header exists but couldn’t be decoded.

400 Version Mismatch

Payment version doesn’t match requirements.

402 Verification Failed

Payment signature or amount was invalid.

Tips

Elysia’s store is shared across all middleware and routes. Payment info will be available in any route handler after the middleware runs.