Skip to main content

Getting started with Next.js

Start accepting x402 payments in your Next.js app in 2 minutes.
For the fastest setup, use the official starter: @payai/x402-next-starter.

Step 1: Create a new app from the starter template

Use your favorite package manager.
npm (npx)
pnpm
bun
The starter bootstraps a production-ready Next.js app with x402 payment middleware already wired up.

Step 2: Set your environment variables

In your generated project, copy the example env and fill in your values:
Update .env.local with:
  • FACILITATOR_URL: Facilitator base URL (defaults to: https://facilitator.payai.network)
  • NETWORK: Network to use for the facilitator (e.g. base-sepolia, base, solana-devnet, solana)
  • ADDRESS: Wallet public address to receive payments to (e.g. 0x... for Base, So11111111111111111111111111111111111111112 for Solana)

Step 3: Explore the generated app

The starter includes a minimal example showing both a free API route and premium content protected by x402.
  • Adjust pricing, networks, and protected paths in middleware.ts.
  • Add your own protected pages under app/premium/* or secure API routes under app/api/*.

Step 4: Run the app

Your Next.js app is now accepting x402 payments!

Step 5: Test the server

You can test payments against your local app by following the fetch example or the axios example.

Need help?

Join our Community

Have questions or want to connect with other developers? Join our Discord server.