← Back to templatesMaintainer pick
x402 Next.js Paywall
Payment-gated Next.js API routes with a CIP-30 browser paywall, via the x402 standard on Cardano preprod.
New to x402 on Cardano? The x402 page has the full picture.
Get started
You need Node.js 20+, a free Blockfrost project id, and a CIP-30 wallet extension such as Eternl or Lace, set to preprod and funded from the preprod faucet. The wallet is what pays in the browser.
- Scaffold the project into a new
my-appfolder:Terminalnpx giget@latest gh:cardano-foundation/developer-portal/examples/templates/x402-next my-app - Install dependencies, then set a seller address and your Blockfrost project id in .env:Terminal
cd my-app npm install cp .env.example .env - Start the local facilitator and the dev server, in two terminals:Terminal
npm run facilitator npm run dev - Open http://localhost:3002 and pay a route from your wallet.
Two priced routes come wired: 1 tADA on /api/message and 0.10 tUSDM on /api/message-usdm. Expect 20 to 60 seconds for on-chain confirmation.
Read the template README on GitHubSpotted something off?
This directory is open source. Open a pull request to update or correct this entry.