Prerequisites

To complete this guide, you will need the following:

1. Create a Node.js project

Start with a brand new empty directory called node-example and run the following command to initiate a Node.js project:

npm init -y

2. Install @zbd/node Node.js SDK

Install ZBD:

3. Send and receive Bitcoin

Create a new file called index.js and add the following code:

import { zbd } from "@zbd/node";

const ZBD_API_KEY = 'b7YW3s2JzZKGcXjIf5Dqof8wjKT2RuWr8';
const ZBD = new zbd(ZBD_API_KEY);

(async function () {
  try {
    // @ts-ignore
    const data = await ZBD.createCharge({
      amount: "100000", // 100 satoshis (100,000 msats)
      description: "Express + ZBD!",
    });

    console.log(data);
  } catch (error) {
    console.error(error);
  }
})();

Run the following command to start your Node.js server:


You may need to add a start script to your package.json file such as node index.js.

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.

lnbc1u1pjdlax9pp5t7jhkd7h2wntd4f2v7xp22dknmjxp0q8nm7hfcny4p7a5mr7x3rsdp9f4hkueteypshggrfde6x2unwv46zqumsv4jkgcqzzsxqzjcsp5dsayu6m6632p28rnkeeqsr7d54amrkv6wh46yrv42gdgca8xl8gs9qyyssqgj2zrkax733rzulfkzc5mqsr8fpwrva82stpa7e0frw32722trv37jlq8mvlqfp8y75lr6mz63zd7qnxar8hhsehuy22pvfq6wjxwqqqa60lx3
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.

3. Try it yourself

You can now send and receive instant Bitcoin payments using Express.js + ZBD!