Lightning for Builders Foundations

Getting started: your lab and your first payment

Start the four-node lab on your laptop, connect it to this page, and make Dina's first invoice and Alice's first payment.

40 minBeginner2 / 17

Draft: this lesson is still waiting for review.

What you'll learn

  • Start the lab and pair it with the lesson page
  • Create a Lightning invoice from the command line
  • Pay an invoice across the network and read the result

Key terms

invoice (ankara)
A Lightning payment request, often shown as a QR code, with an amount and an expiry time.
node (nodi)
A computer running Bitcoin or Lightning software that checks every rule for itself.
regtest
A private Bitcoin test network you control, where blocks are mined instantly.

In the book, Alice buys a coffee from Bob's café with a phone wallet. Here you play every part. Your lab has four nodes on regtest: Alice and Dina run LND, Bob and Chan run c-lightning, and they are already linked in a line, Alice → Bob → Chan → Dina.

Step 1: Start the lab

In a terminal (on Windows, inside WSL2):

git clone https://github.com/comwanga/bitsacco-jifunze
cd bitsacco-jifunze/lab
./lab doctor     # checks Docker, memory, disk and port 7777
./lab up         # starts the nodes; the first run downloads about 2 GB

./lab up ends by printing a pairing code like ABCD-EFGH-JKLM. Paste it into the lab bar at the top of this page and press Connect. You should see six green chips: bitcoind and the four nodes.

Step 2: Dina asks to be paid

An invoice is a payment request. Dina makes one for 50,000 sats:

Dina creates an invoice

These exercises need a laptop with the lab running. You can read the lesson on your phone.

Look at the output: payment_request is the invoice text (it starts with lnbcrt, for Lightning on regtest), and r_hash is the hash of a secret only Dina knows.

Step 3: Alice pays

Copy Dina's payment_request into the next exercise, replacing INVOICE, and run it. The --force flag skips the "are you sure?" question.

Alice pays Dina's invoice

These exercises need a laptop with the lab running. You can read the lesson on your phone.

The table in the output shows the route: Alice → Bob → Chan → Dina, with a tiny fee for each hop. Payment status SUCCEEDED and a preimage mean Dina was paid: in lesson 8 you'll see why that secret is the receipt.

If something gets stuck, press Reset lesson on any exercise to restore this lesson's starting channels.

Reflect

Write your answer down, or talk it over with a friend or your chama.

  1. What did the payment output tell you about the route? Which nodes did it pass through?
  2. Why is it safe to show an invoice to anyone, but not a seed phrase?

Check yourself

Question 1 of 4How does a regtest invoice start?

Further reading

Adapted from Mastering the Lightning Network. Andreas M. Antonopoulos, Olaoluwa Osuntokun and René Pickhardt. Licence: CC BY-SA 4.0.