Skip to main content

Installation

Quick Start

Create middleware.ts in your project root:
Every request to /api/* is evaluated before reaching your route handler. Wallets that fail the trust check receive a 402 or 403 response at the edge — your API handlers only see trusted traffic.

Configuration

Wallet Address Extraction

By default the middleware checks:
  1. X-Wallet-Address request header
  2. ?wallet= query parameter
Override with extractWallet:

Response Headers

Requests that pass trust checks get these headers set on the response: Read these in your API route handlers:

Route Matching

The matcher option controls which routes are trust-gated. Routes that don’t match pass through without evaluation.
Also set config.matcher in your middleware.ts export so Next.js only runs the middleware on matching routes. This avoids unnecessary edge function invocations.

Failure Responses