To complete this guide, you will need the following:

1. Create a Next.js Project

Follow the prompts on the create-next-app CLI to create a new project, and then change into the directory of your project.

yarn create next-app <project-name>
cd <project-name>

2. Write an Edge Function

For this guide we will be making use of the App Router inside of Next.js.

Create a new file in the app/api/request/route.ts that creates a Bitcoin Lightning Charge (payment request) with the following code:

import { NextResponse } from 'next/server';

export const runtime = 'edge';
export const dynamic = 'force-dynamic';

const ZBD_BASE_URL = '';
const ZBD_API_KEY = 'b7YW3s2JzZKGcXjIf5Dqof8wjKT2RuWr8';

export async function GET() {
  const res = await fetch(`${ZBD_BASE_URL}/v0/charges`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'apikey': `${ZBD_API_KEY}`,
    body: JSON.stringify({
      amount: '100000', // 100 satoshis (100,000 msats) -- ~$0.03
      description: 'Money at internet speed', // What is this payment request for?

  if (res.ok) {
    const data = await res.json();
    return NextResponse.json(data);

3. Create payment request locally

Run function locally:

npx next dev

Opening your browser to the following URL: http://localhost:3000/api/request should return a JSON response with a payment request.

You can also test this using curl command:

curl http://localhost:3000/api/request

You’re looking for the data.invoice.request property in the JSON response. It starts with lnbc1 and is the payment request anyone in the Bitcoin Lightning Network can use to pay you.

Charges and payment requests are usually shown to users as QR codes that can be scanned by mobile apps (e.g. ZBD). Read Callbacks to understand how to receive updates about your payment asynchronously.

4. Create payment request in production

Deploy your project to Vercel:


Opening your browser to the following URL: should now return this in production.

You can also test this using curl command:


5. Try it yourself

You can now begin receiving instant Bitcoin payments on the edge with Vercel + ZBD!