Lightning Network Tutorial : From Scratch to a LND Transaction

Lightning Network Tutorial : From Scratch to a LND Transaction

By Gustavo J. Flores Echaiz over 3 years

Last week, we illustrated the Lightning network protocol, BOLTs (Basics of Lightning Technology), through a visual diagram that we hope has contributed to the community’s understanding of this technology. If you didn’t have time to check it out, don’t hesitate to give it a quick look here!

This week, we want to get into the implementation of this technology to understand how it works in the real world. We have built tutorials for both major implementations, LND & C-lightning. To view the c-lightning one, click here.

LND is a complete implementation of the protocol of the Lightning Network. It is an open-source project that anyone can contribute if you follow the guidelines and it is maintained and mostly done by Lightning Labs Inc. LND is a command line software, which means there is no GUI (Graphical User Interface) integrated in it, it is meant to work as a back-end server (node) for other applications that could bring the GUI. It is also a bitcoin mainnet wallet and a lightning network wallet.

This tutorial will provide a step-by-step guide to LND.

Windows or MacOS

First of all, to run LND locally on your Windows 10 or MacOS computer, refer to Pierre Rochard’s Node Launcher, it is a very straightforward software that will execute very easily and you don’t even have to install bitcoind beforehand it will do all for you. You can always contact us if you have difficulties using it.

For Linux, it goes differently, so here is a tutorial to install LND on a Debian-based machine like Ubuntu 18.04. I will always be using bitcoind as the backend.

Linux part 1 : Setting up Bitcoind

To install bitcoind on a linux machine like ubuntu, refer to StopandDecrypt awesome step-by-step guide on Medium, this is far better from anything I could have written. In this process, he completely builds from source while verifying the authenticity of the packages.

If you don’t want to build from source for whatever reason, there is an easier way to install bitcoind and bitcoin-qt (GUI version), you simply have to run these commands :

sudo apt-add-repository ppa:bitcoin/bitcoin
sudo apt-get update
sudo apt-get install bitcoin-qt bitcoind

Once it is installed, you can create a configuration file by running this command.

 nano ~/.bitcoin/bitcoin.conf

My configuration file looks like this and it is the minimum necessary to run lnd :


You can also modify your configuration file with this great tool by Jameson Lopp.

You can then launch bitcoind by simply entering this in the cli.


Or for the gui version :


You have now launched bitcoind, and it has started syncing the blockchain. This can take several days, to check its progress, enter this command :

bitcoin-cli getblockchaininfo

Once this step is finished, you are ready to move forward to LND.

Part 2 : Installing LND

You can pretty much follow this tutorial step-by-step and it will work, but I will do my own version too.

First off, install Git and Make which will be necessary to install LND. Then download Go as an encrypted package.

sudo apt-get install git make
sudo apt-get update
sha256sum go1.11.5.linux-amd64.tar.gz | awk -F " " '{ print $1 }'

The output of the last command should be : ff54aafedff961eb94792487e827515da683d61a5f9482f668008832631e5d25.

If it matches, it is the right package and you can proceed with its installation by extracting it first.

tar -C /usr/local -xzf go1.11.5.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin

Then you will need to set up your $GOPATH environment to the proper directory and to add $GOPATH/bin to your PATH. This simply means that you will be able to use lnd and lncli as direct commands, without indicating their locations. To avoid doing this every time you open a terminal window, do the following :

sudo nano ~/.profile

This will open the file .profile.  Add the following lines at the end of the file, and save it.

export GOPATH=~/gocode
export PATH=$PATH:$GOPATH/bin

Open a new terminal window so that it can take effect and run these commands to install LND.

go get -d
cd $GOPATH/src/
make && make install

Run this command to make sure it was installed properly.

make check

You can then launch lnd to test if it would work.


if this is the output, it means the installation didn’t go well. Check to see that you didn't skip a step. If you didn't and it still doesn't work, you can either contact us through Twitter for a quick response or ask for help in LND's Slack Channel.

But if the following is the output instead, it is installed and you can proceed into the next part.

Part 3 : LND configuration file

This step is about modifying the LND configuration file according to your needs. First to create a config file, run this command.

nano ~/.lnd/lnd.conf

A text file will open inside your terminal. You can input the desired configuration in this file, to find all the potential properties, click here. If you wish to keep it simple as I did, here is my configuration file, the first is necessary, the second part is optional if you wish to receive incoming transactions from the network and the third part is if you wish to connect a wallet on another device to LND.


Save this file and your configuration is ready.

Part 4 : Launching LND

You can then launch lnd in various ways.

Either in a regular way, but you will have to open a new terminal window to use lncli and if you close the first terminal window, lnd will shut down.


Either as a background, but once you close the terminal, lnd will shut down. you should also tail the log file.

lnd &
tail $HOME/.lnd/logs/bitcoin/mainnet/lnd.log

Last option is to run lnd in the background and that it doesn’t shut down when you close the terminal window, run this command if this is what you wish.

nohup lnd > /dev/null 2> /home/USERNAME/.lnd/err.log &

Either of these commands will make lnd launch for the first time, so you will have to create a password. In the first scenario, you will have to open a new terminal, in the other two, you can simply continue on the same terminal. Enter the following command and follow the steps.

lncli create

Back up your 24 words seed generated safely. Keep in mind that this is only a backup for your bitcoin main net coins and not your lightning channels. Then unlock your wallet with this command :

lncli unlock

LND will sync with the network, this might take some time, around half an hour. You can check its state with this command. Once this becomes true, you are synced and ready to proceed.

lncli getinfo

Part 5 : Network and Port Configuration

To allow incoming connections for your bitcoin node and your lightning node, you need to have 8333 and 9735 ports open and correctly forwarding to your respective nodes.

Pierre Rochard’s has written an article that should answer all your questions about port forwarding for bitcoin and lightning.

This part is obviously optional, but if you decide to do it, here is a complete guide about it.

To check if your ports are open, use this simple tool.

Part 6 : Depositing Funds in the BTC wallet

Back to LND, let’s deposit funds in the BTC wallet. First you have to generate an address, it can either be a np2wkh or a p2wkh. They are both segwit addresses, p2wkh being native segwit and np2wkh starts with a 3 and is compatible with wallets that don’t support segwit. So if you’re withdrawing from most exchanges, you would have to use a np2wkh address since they still aren’t segwit compatible. So run either of these commands depending on your needs.

lncli newaddress np2wkh
lncli newaddress p2wkh

Simply paste the address on your other bitcoin wallet and choose the desired amount.

If you want to convert it to a QR CODE format, there is a simple way one can do this with a program called qrencode.

sudo apt-get install qrencode
qrencode -o qrcodefilename.png ‘ADDRESS’

Simply replace ADDRESS with your address, and replace the file name, and the QR code will be available in the folder you are located. You can do this for pretty much everything else, like a node public key, an invoice, etc.

Once you make the transaction on your other wallet, you can check if the funds are available by entering either one of these commands, they all pretty much define themselves :

lncli walletbalance
lncli listchaintxns
lncli listunspent

Once your balance is confirmed, you can open a channel to use the lightning network.

Part 7 : Opening a Channel

I have chosen Pierre Rochard’s LightningPowerUsers node as an example since it is one of the best nodes in the network.

First, connect on the p2p layer to the other node by running this command :

lncli connect 0331f80652fb840239df8dc99205792bba2e559a05469915804

You make sure you are well connected by running this command:

lncli listpeers

Then, to open a channel with this peer, run this command :

lncli openchannel --node_key= 03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370
e2c366597a3f8f --local_amt=10000

You can check it’s confirmation status by running either one of these commands :

lncli channelbalance
lncli listchannels

Once your transaction gets enough confirmations on the base layer, you are ready to finally use the lightning network!

Part 8 : Make a Transaction

Let’s test with the Lapp, choose a random article and select Pay to Continue Reading.

Copy the payment request and paste it on this command :

lncli sendpayment --pay_req=PASTE_IT_HERE

It will ask you to confirm, simply input: yes.

There you go, you have completed your first lightning transaction on LND!

Part 9 : Receive a Payment

To receive a payment, you have to either have an incoming channel or to have pushed funds on the other side of the channel by making a payment. First off, if you don’t have anyone that will make an incoming channel to your node, LightningPowerUsers will do it if you make an outcoming channel to the node first, to find out more, check out the website here.

Keep in mind that you will have to have your port 9735 open and forwarded for someone to make an incoming channel to you. You can also just spend money on your outcoming channel, and that money spent will be able to be paid back to you by other nodes that can route to yours or by the node you are connected to.

To make an invoice, run this command, replace 50000 by the number of satoshis you wish to invoice :

 lncli addinvoice 50000

To verify you have received the payment, run this command :

lncli listinvoices

I hope you have enjoyed this tutorial, contact us on Twitter if you have any issues and we will help you with our highest capacity.


History and Current State Review of Schnorr Signatures for Bitcoin

History and Current State Review of Schnorr Signatures for Bitcoin

Bitcoin developers want to implement Schnorr Signatures to Bitcoin. Learn about their history and how they improve malleability and scalability.


Maciej Cepnik

3 min read


Visualizing BOLTs : Basics of Lightning Technology

Visualizing BOLTs : Basics of Lightning Technology

Going through the BOLTs can be a complicated and long task so We decided to construct a framework that would make it easier for everyone to understand it. We present a minimalistic approach to understand how the Lightning Network works.


Maciej Cepnik

3 min read

Montreal, Quebec, Canada
MSB License: M20484233


  • © Veriphi Inc. 2021 All rights reserved
  • Terms of Service
  • Privacy & Security