Mastering Lightning Network - Week 1: Generating Lightning InvoiceMastering Lightning Network - Week 1: Generating Lightning Invoice
OverviewOverview
In this first week you will:
- Set up Bitcoin Core and Core Lightning (CLN) nodes using Docker.
- Interact with both Bitcoin Core and Lightning nodes on
regtest. - Fund a Lightning node and create a BOLT11 invoice.
- Output a small report file named (
out.txt) in the current dicectory demonstrating you can fund a Lightning node and generate valid invoices. - Target Locations for the solution code for each language are given below:
- Bash:
solution.sh - JavaScript:
index.js - Python:
main.py] - Rust:
main.rs
- Bash:
Problem StatementProblem Statement
Lightning Network is a Layer 2 payment protocol built on top of Bitcoin. Before a Lightning node can send or receive payments, it needs to have on-chain Bitcoin funds and create payment channels. The following exercise introduces us to the basics of setting up and funding a Lightning node.
We will be using Docker to set up Bitcoin Core and Core Lightning nodes, after which we fund the Lightning node with regtest Bitcoin and generate a BOLT 11 Lightning invoice
Solution RequirementsSolution Requirements
You need to write code in any one of bash, javascript, python or rust that will do the following:
Setup - Docker ComposeSetup - Docker Compose
The assignment uses Docker Compose to run both Bitcoin Core and Core Lightning nodes. The configuration is provided in docker-compose.yml.
Services:
- bitcoind: Bitcoin Core node running on regtest
- RPC port: 18443
- RPC credentials: alice/password
- cln (ln-node): Core Lightning node
- Connected to bitcoind
- Network: regtest
To start the services:
docker compose up -dTo stop the services:
docker compose down -vNode Interaction - Choose ONE LanguageNode Interaction - Choose ONE Language
Implement the tasks in exactly one of the language-specific directories: bash, javascript, python, or rust.
Each implementation uses helper functions located in the directories.
Your program must:
- Create a new Lightning address
- Create a mining wallet exists and generate a new address from the mining wallet
- Mine new blocks to this address until you get positive wallet balance. (use
generatetoaddress) (observe how many blocks it took to get to a positive balance) - Write a short comment describing why wallet balance for block rewards behaves that way.
- Fund the Lightning node from the mining wallet and confirm the transaction
- Verify Lightning wallet balance and create a Lightning invoice
OutputOutput
Output the following invoice details to out.txt in the root directory. Each attribute should be on a new line:
- Payment hash
- BOLT11 invoice string
- Amount in millisatoshis
- Description
- Expiry time