x402-next
Next.js middleware integration for the x402 Payment Protocol. This package allows you to easily add paywall functionality to your Next.js applications using the x402 protocol.Installation
Quick Start
Create a middleware file in your Next.js project (e.g.,middleware.ts):
Configuration
ThepaymentMiddleware function accepts three parameters:
payTo: Your receiving address (0x${string})routes: Route configurations for protected endpointsfacilitator: (Optional) Configuration for the x402 facilitator servicepaywall: (Optional) Configuration for the built-in paywall
Middleware Options
Route Configuration
Payment Configuration
Example with API Routes
Create protected API routes in your Next.js application:App Router Support
The middleware works with both Pages Router and App Router:App Router (app directory)
Pages Router (pages directory)
Deployment Considerations
Vercel
The middleware works seamlessly with Vercel’s Edge Runtime:Other Platforms
The middleware is compatible with any platform that supports Next.js middleware:- Netlify
- AWS Amplify
- Railway
- Self-hosted deployments