⚡ The Lightning Network, Part #2: Running A Bitcoin Lightning Node on Raspberry Pi

by installing the Lightning Labs lnd release binary

Ishaana Misra
Coinmonks
Published in
7 min readAug 31, 2021

--

The Lightning Network is a network of decentralized off-chain micropayment channels that can be layered on top of any blockchain-based cryptocurrency like Bitcoin.

Running a lightning node is not only a simple way to transfer funds instantly using Bitcoin, it’s also a cool way to learn about how the lightning network works!

To learn more about The Lightning Network, you can check out part #1 of this series:

Running A Bitcoin Node On Raspberry Pi

The Lightning node will run on top of the Bitcoin blockchain, so in order to run a lightning node, you already need to be running a Bitcoin node. You can check out this article for more information:

Once you are running bitcoind on your Raspberry Pi, we can get started!

Installing A Release Binary

In order to run a node, we need to run lnd, the Lightning Network Daemon from Lightning Labs. There are three main ways to go about doing this: installing a release binary, building it from source, and building it manually. I chose to install a release binary since that was easiest and I didn’t need the benefits provided by using one of the more advanced methods.

A release binary is a compiled version of the source code which the computer can read. A source release on the other hand, hasn’t been compiled and requires you to do so. Because it has already been compiled, the binary release that you install must match your operating system.

The first thing that I did on my Raspberry Pi terminal was change my directory to Downloads to keep things organized. Then, I went to the lnd releases page and found the latest release. I went to the “assets” section at the bottom and copied the link address for “lnd-linux-arm7”. I then ran wget [link] to download the zip file:

$ wget https://github.com/lightningnetwork/lnd/releases/download/
v0.13.1-beta/lnd-linux-armv7-v0.13.1-beta.tar.gz

Verifying The Release

Before we unzip the file, we need to make sure that it wasn’t modified, and that it’s the correct file we meant to download. In order to verify a release, we can get the hash of the zip file and compare it to the hash we know the file is supposed to have. You can learn more about hashing here.

First, I downloaded the two following files from the same “releases” page on the lnd Github repository :

$ wget https://github.com/lightningnetwork/lnd/releases/download/
v0.13.1-beta/manifest-roasbeef-v0.13.1-beta.sig
$ wget https://github.com/lightningnetwork/lnd/releases/download/ v0.13.1-beta/manifest-v0.13.1-beta.txt

Next, I imported the keys which signed the release like this:

$ curl https://keybase.io/bitconner/pgp_keys.asc | gpg --import
$ curl https://keybase.io/roasbeef/pgp_keys.asc | gpg --import

To verify the file containing the correct hashes, I ran:

$ gpg — verify manifest-roasbeef-v0.13.1-beta.sig manifest-v0.13.1-beta.txtgpg: Signature made Mon 19 Jul 2021 05:41:37 PM EDTgpg:using RSA key 60A1FA7DA5BFF08BDCBBE7903BBD59E99B280306gpg: Good signature from "Olaoluwa Osuntokun <laolu32@gmail.com>" [unknown]gpg: WARNING: This key is not certified with a trusted signature!gpg: There is no indication that the signature belongs to the owner.Primary key fingerprint: E4D8 5299 674B 2D31 FAA1  892E 372C BD76 33C6 1696Subkey fingerprint: 60A1 FA7D A5BF F08B DCBB  E790 3BBD 59E9 9B28 0306

Finally, I got the hash of the zip file and compared it to the corresponding hash in the text file.

#got hash
$ shasum -a 256 lnd-linux-armv7-v0.13.1-beta.tar.gz
76075aabb5dc13cb93b95ecb560e94d393e8efbd9d17db83b014b4cd87d57211 lnd-linux-armv7-v0.13.1-beta.tar.gz#checked hash under "lnd-linux-armv7-v0.13.1-beta.tar.gz" to make #sure the hash received above corresponds with that one
$ nano manifest-v0.13.1-beta.txt
76075aabb5dc13cb93b95ecb560e94d393e8efbd9d17db83b014b4cd87d57211 lnd-linux-armv7-v0.13.1-beta.tar.gz

Placing The Release In .lnd

First, make a directory within your bitcoind data directory called “lnd-data”. Next, return to the home directory and create a “.lnd” directory which will be used as a symlink by running ln -s /mnt/data/lnd-data .lnd. A symlink, also known as a symbolic link, allows you to access one directory from multiple places, making it easier to navigate.

Now, return to “Downloads” and move the “lnd-linux-armv7-v0.13.1-beta.tar.gz” file to .lnd by running mv lnd-linux-armv7-v0.13.1-beta.tar.gz ~/.lnd. Next, return to “.lnd” and unzip the file. Go to the new directory created, “lnd-linux-armv7-v0.13.1-beta/”, and you should see two files, “lnd” and “lncli”. Move these files to “.lnd” and delete the now empty folder they were in previously

Configuring lnd By Modifying lnd.conf & bitcoin.conf

Within .lnd, we need to create a configuration file which contains the settings for our Lightning node. In order to do so, I ran sudo nano lnd.conf to create and enter the file. There, I wrote the following:

[Application Options]
maxpendingchannels=10
alias=YOUR_ALIAS
color=#9999ff #or another color
maxlogfilesize=10
[Bitcoin]
bitcoin.active=1
bitcoin.mainnet=1
bitcoin.node=bitcoind #specifying which bitcoin daemon we're using
[Autopilot]
autopilot.active=0
autopilot.maxchannels=10
autopilot.allocation=1.0
[Tor]
tor.active=true
tor.v3=true
tor.streamisolation=true

Note: your alias is just a public name for your Lightning node

We also need to update the Bitcoin configuration file so that bitcoind can work with lnd. First, I went to the .bitcoin directory and run sudo nano bitcoin.conf. Then, I appended the following to the file:

zmqpubrawblock=tcp://127.0.0.1:28332zmqpubrawtx=tcp://127.0.0.1:28333

This allows lnd to communicate with bitcoind using ZeroMQ. Finally, I went back to the home directory and restarted the Bitcoin daemon by running bitcoin-cli stop, and then running bitcoind -daemon.

Running lnd

In order to run lnd, you just need to enter lnd , but before running lnd, we need to create a wallet. Doing so is fairly simple, just enter lncli create and follow the instructions to create a wallet. Then, I ran lnd and watched it start up.

Opening A Channel With Another Node

In order to open a channel with another node, all you need is the node’s alias. Once you have the alias(which you can simply ask the node’s owner for) you can go to 1ml.com, a lightning network search engine that allows you to find information about individual nodes, and search for the node alias. It looks like this:

From this page, we’ll need two pieces of information: the Public Key, and the IP Address. Using this information, enter the following command on your terminal:

$ lncli openchannel --node_key PUBLIC_KEY --connect IP_ADDRESS --local_amt X

The local_amt parameter is the amount of Sats that you want to commit to the channel.

Sending & Receiving Bitcoin/Satoshis

Once you have a channel open with another node, you can send Sats back and forth without any transaction fees.

There are two ways of doing this: sending payments with invoices, and using keysend.

Method #1: Invoices

In the lightning network, an invoice is an encrypted payment request. Two people, Alice and Bob have opened a payment channel as shown above. Let’s say that Alice just bought coffee from Bob and Bob wants to be payed 1,000 Sats. In order to do so, Bob creates an invoice by running lncli addinvoice --amt=1000 --memo="coffee". The “amt” field contains the amount of Satoshis, and the “memo” field contains a message, so that Alice knows what she’s paying for.

Bob can now message Alice the “payment_request”. From here, Alice can run lncli sendpayment --pay_req=PAYMENT_REQUEST on her lightning node in order to send Bob the Sats. That’s it! Bob instantly has 1,000 more Sats.

Method #2: keysend

Using this method, the recipient doesn’t need to give the sender a payment request. Instead, all the recipient has to do is enable keysend on their node by running lnd with the flag --accept-keysend. Doing this is pretty straightforward, just run lnd --accept-keysend.

Now, the sender can run lncli sendpayment --keysend --dest [PUBLIC KEY] — amt [SATS].

In order to check you channel balance, you can run lncli channelbalance, and in order to check your wallet balance, run lncli walletbalance. Your channel balance will transfer to your wallet when you close the channel. To learn about other commands, you can just run lncli.

About Me

Ishaana Misra is a high school freshman interested in AI, Medicine, and Blockchain.

Twitter: https://twitter.com/IshaanaMisra

Check out my newsletters: https://ishaana.substack.com

Join Coinmonks Telegram Channel and learn about crypto trading and investing

Also, Read

--

--

Ishaana Misra
Coinmonks

Student at Stuyvesant learning about cryptography and Bitcoin.