academy lnbits


In this optional session, we are going to install LNbits. LNbits is an accounting system with countless useful functionalities. It allows you to “open” your node to others, such as family and friends, who can each have their own custodial wallet, you being the custodian. You can connect your LNbits wallet to Bluewallet or Zeus, and install countless extensions, many of which make use of LNURLs.

Useful resources:


To make use of LNbits, your server needs to be accessible through an IP address (ideally both IPv4 and IPv6). You will also need a domain name. If you already have a domain name but use it for something else such as your website, you should be able to create a subdomain free of charge and point it at your LNbits installation.

If you don’t have a domain name and always wanted one, you can buy domains with Namecheap with sats. I use Cloudflare for free DNS.

Furthermore, we need to download some additional software:

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.9 python3.9-distutils
curl -sSL https://install.python-poetry.org | python3 -
export PATH="/home/ubuntu/.local/bin:$PATH"

(Depending on your setup, the last command might look slightly different. The output of the previous command should give you the correct example.)

Download LNbits

We will navigate to our git directory and clone the LNbits repository.

cd ~/git
git clone https://github.com/lnbits/lnbits.git
cd lnbits
git checkout <latest version, e.g. 0.10.9>

Install LNbits

Next, we are going to install LNbits

poetry env use python3.9
poetry install --only main

Configure LNbits

We configure LNbits by first creating a data directory, then copying and editing the default configuration file.

mkdir data
cp .env.example .env
nano .env

Next we will have to find and amend the following four lines in this file:


Run LNbits

We can run LNbits for the first time using simply:

poetry run lnbits

This should give us an indication of whether LNbits is properly set up. We can stop LNbits with Ctrl + C, but for now, we’ll keep it running, and instead open a new terminal shell.

Install the reverse proxy

We are going to use Caddy as the reverse proxy. If you’re experienced in configuring Apache or Nginx, you may also use those. You can find some additional guides here.

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

As caddy is now installed, it is also running already! We will have to stop caddy to change its configuration.

sudo caddy stop
sudo nano /etc/caddy/Caddyfile

We can use the following configuration file. Make sure to replace lnbits.nodeacademy.org with your own domain name!

lnbits.nodeacademy.org {
  handle /api/v1/payments/sse* {
    reverse_proxy {
      header_up X-Forwarded-Host lnbits.nodeacdemy.org 
      transport http {
         keepalive off
         compression off
  reverse_proxy {
    header_up X-Forwarded-Host lnbits.nodeacademy.org

Next, we will have to point the DNS records of this domain to our IP address. We can find our IP address in the admin panel of our VPS provider, e.g. Lunanode.

In our example, the records are (IPv4) and 2602:ffb6:4:c927:f816:3eff:fee5:e984 (IPv6).

We will point the A (IPv4) and AAAA (IPv6) records of our domain to this IP address. Check with your domain registrar or DNS provider.

Finally, we are going to start caddy. We have to make sure to be in the right directory when we do that!

cd ~/git/lnbits
sudo caddy start

If we have configured a firewall (UFW), then we also have to open ports 80 and 443!

sudo ufw allow http
sudo ufw allow https

First steps with LNbits

We will now need to find out what the id is of the admin users. To do that, we will run:

cd ~/git/lnbits
poetry run lnbits-cli superuser

We should see a string of letters. We will navigate to our LNbits installation, e.g. https://lnbits.nodeacademy.org/wallet?usr=stringofletters. Just substitute your domain and your string with this one. Check on the left if you see the “Admin” option. Under “Manage Server” you can configure your server further. Explore this!

Make sure to bookmark this wallet in your browser! Anybody with access to this bookmark can access your LNbits server, so be careful! You can also rename the wallet to “Admin” on the right.

LNbits admin

Now let’s make a regular user. Go to your LNbits installation, such as https://lnbits.nodeacademy.org. Enter a wallet name, such as your name, and click on “Add New Wallet.” Bookmark this wallet!

All extensions need to be first installed by the admin user. Then they can be enabled by each individual user.

To add funds into your wallet, you can use the Admin user. Next to the balance is a + sign. This lets you change the balance of the admin wallet, from where you can send it out to individual users. Be careful not to “create” more funds than you have in your Lightning node!

Configure LNbits with systemd

First we are going to shut down LNbits, if it’s still running. We can do that with Ctr + C in the window that it’s running.

We are going to create a service file

sudo nano /etc/systemd/system/lnbits.service

Here’s a service file we can use:


ExecStart=/home/ubuntu/.local/bin/poetry run lnbits --port 5000


We’ll save it with Ctrl + O and close the editor with Ctrl + X.

To activate the file, we are going to run:

sudo systemctl enable --now lnbits.service

We should see the following output: Created symlink /etc/systemd/system/multi-user.target.wants/lnbits.service → /etc/systemd/system/lnbits.service.

We can check if its running now with systemctl status lnbits.service and refresh the wallet we have open in our browser.

Now try restarting the machine and see if everything comes online by itself, including Bitcoin Core, LND and LNbits!

Update LNbits

LNbits regularly releases new updates with patches and new features. To update, first navigate to where you downloaded the LNbits source code.

cd ~/git/lnbits

We will get the latest code and checkout the latest version. Observe the output of the git checkout command to see which versions are new!

git pull
git checkout 0.11.3

First we will update poetry before we update lnbits itself.

poetry self update
poetry install --only main

The output should look something like this:

Installing dependencies from lock file

Package operations: 1 install, 13 updates, 0 removals

  • Installing bitarray (2.8.4)
  • Updating exceptiongroup (1.1.3 -> 1.2.0)
  • Updating idna (3.4 -> 3.6)
  • Updating wrapt (1.15.0 -> 1.16.0)
  • Updating bitstring (3.1.9 -> 4.1.4)
  • Updating certifi (2023.7.22 -> 2023.11.17)
  • Updating charset-normalizer (3.3.0 -> 3.3.2)
  • Updating cryptography (41.0.4 -> 41.0.7)
  • Updating importlib-resources (6.1.0 -> 6.1.1)
  • Updating urllib3 (2.0.6 -> 2.1.0)
  • Updating limits (3.6.0 -> 3.7.0)
  • Updating outcome (1.2.0 -> 1.3.0.post0)
  • Updating pyln-proto (23.5.2 -> 23.11)
  • Updating lnurl (0.3.6 -> 0.4.2)

Installing the current project: lnbits (0.11.3)

Finally, we will have to restart LNbits, assuming we have set up systemd as explained above.

sudo systemctl restart lnbits.service

You should now be able to navigate to your LNbits installation and confirm you are running the installed version at the bottom of the screen.

© 2024 Vancouver Bitcoiners   •  Powered by Bitdevs Vancouver   •   Theme  Moonwalk