If you want to learn more about the Lightning Network, have a look at the following video where Thaddeus Dryja explains it in details.
For the purpose of the tutorial, I'll be using Ubuntu 17.04 but these steps should work on most Debian-based distributions.
#1 Install Go lang and dependencies
If you haven't done so already, install Go with apt:
sudo apt-get install golang-1.10-go
Alternatively, you may build it from source.
Create a folder that will hold all Go apps:
Export Go paths:
echo "export GOPATH=~/go" >> ~/.bashrc
echo "export PATH=$GOPATH/bin:/usr/lib/go-1.10/bin:$PATH" >> ~/.bashrc
Check that Go is installed properly and the path is recognized:
The output should be
go version go1.10 linux/amd64.
#2 Install LND
Next, run the series of commands to install LND from source:
git clone https://github.com/lightningnetwork/lnd $GOPATH/src/github.com/lightningnetwork/lnd
go install . ./cmd/...
To update LND in the future run these commands instead:
git pull && dep ensure
go install . ./cmd/...
#3 Configure LND
It's important that you create your own Lightning Network configuration.
Start by creating the config file:
mkdir ~/.lnd && cd ~/.lnd
Open the config file in an editor of your choice and add the following lines:
alias=A name for your node
Make sure that
bitcoind.rpcpass match your environment.
#4 Configure bitcoind
If you haven't done so, install bitcoind first.
Alternatively, you can compile it from source with the ZeroMQ support. The article is written for Raspberry Pi3 but could work on most debian-based distributions.
Once your full bitcoin node is set up make sure
~/.bitcoin/bitcoin.conf contains this minimal configuration:
Run the node.
#5 Make LND accessible from the outside world
Allow TCP and UDP traffic on port 9735:
sudo iptables -A INPUT -p tcp --dport 9735 -j ACCEPT
sudo iptables -A INPUT -p udp --dport 9735 -j ACCEPT
and permanently save your settings:
If your machine is behind a router, you will also have to forward ports to it.
Each router is different so you will have to figure it out on your own. Generally, you will want to look for Port Forwarding/Virtual Server settings under WAN.
#6 Setup LND as service
This step is kind of tricky since it's recommended to encrypt your lightning wallet with a password. Thus, lnd can't be started automatically after the system restart because your interaction is needed.
However, I like to manage daemons with Systemd so I still wrote a service script for it.
sudo wget https://gist.githubusercontent.com/mariodian/f766645710c1f6922c429f751869e744/raw/56c82bae3bdf727d82db6f82ba22e717623510f9/lnd.service
Make sure to edit the following script's variables to match your environment:
sudo systemctl enable lnd
Let's create a script that starts the daemon and prompts for lightning wallet password.
chmod u+x lnd.sh
#7 Run LND
Don't run lnd with the above script yet because you'll need to create a lightning wallet first.
Instead, run lnd with the standard
sudo service lnd start &
Next, create the wallet and follow the on-screen instructions:
You will have to set up a wallet password and write down the wallet's mnemonic seed (important!).
When finished stop the lightning daemon:
sudo service lnd stop
Now that you have created the wallet you can use the above start/stop script to start lnd and unlock the wallet (you'll be prompted for the password):
Similarly, you can stop lnd:
#8 Send bitcoins to the Lightning wallet
You will have to fund your Lightning wallet before you can start using the Lightning Network.
Create a new address:
lncli newaddress p2wkh
Send bitcoins to the address and wait for the network confirmation (usually around 10 minutes).
Check the wallet balance:
and proceed to the next step if
confirmed_balance is of a non-zero value.
#9 Open a channel
Go to the Lightning Network Search and Analysis Engine and choose a random node to open a channel with:
lncli connect <channel pubkey>@<channel ip address>:<channel port>
lncli openchannel <channel pubkey> --local_amt=<amt in satoshi that you commit to>
Alternatively, you can open a channel with our node:
lncli connect email@example.com:9735
lncli openchannel 02241e1d480fcedaa1268574d530ef8ed5545bacdcd391e40ac58cbed30d001d40 --local_amt=1000000
If you get a "connection error" the node is either offline or the initial node discovery have failed.
You can check for potential errors with this command:
tail -f ~/.lnd/logs/bitcoin/mainnet/lnd.log
In the case of DNS SEED errors, you will have to manually establish connections to well-connected nodes first:
lncli connect firstname.lastname@example.org:9735
lncli connect email@example.com:9735
lncli connect firstname.lastname@example.org:9735
Wait a bit and try to open the channel again.
The channel opening needs to be confirmed on the Bitcoin network first. It will show as pending in the meantime:
#10 Make a Lightning Network payment
To make a quick test payment, head over to Y'alls and click the lightning bolt icon to generate a payment request.
Copy the payment address and go back to the console. In my case it is:
lncli sendpayment --pay_req=lnbc1u1pd2efjspp5hg6yv309s8x6wdktsrgjtxskvdp792f9zrp7mv9mwrqp4ce89gksdz22fjkzepqg9e8g6trd3jn5gzjw4hxu6twvusyc6t8dp6xu6t8dp6zqnn9w3mk7untypzxzetdducqzysgsmwrsalmqymptmtl02u7kznlv5ga5cvdgz2d0wzpqjfeqq7t6yseklqevy9xdh6nm2kym95zv6fvsmdypqw480t4x2msplpsdlfvqgpe05x29
The payment should be processed within a second or so.
You can also specify the amount yourself:
lncli sendpayment --pay_req=<payment request> --amt=<amount in satoshi>
As you can see it's not that difficult for an average Linux user to set up and use the Lightning Network.
Having said that, Lightning Network is still a long way to go before it can hit the mainstream. The protocol only entered beta phase recently and more tools will need to be developed for it to be useful for an average Joe.
For more info, head over to the Lightning App Directory.