Lightning Network is a system of smart contracts on top of the Bitcoin's blockchain.
It aims to solve scalability, provides instant payments with zero double spend risk and cheap transactions.
These properties enable new use cases such as decentralized exchange markets via cross-chain atomic swaps and more.
However, Lightning Network is a new protocol with a steep learning curve and it will take a while before new easy to use applications appear.
In the meantime, let's have a look at how to set up a node from scratch and make a simple payment.
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 source ~/.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 cd $GOPATH/src/github.com/lightningnetwork/lnd dep ensure go install . ./cmd/...
To update LND in the future run these commands instead:
cd $GOPATH/src/github.com/lightningnetwork/lnd 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 touch lnd.conf
Open the config file in an editor of your choice and add the following lines:
debuglevel=info debughtlc=true listen=your.ip.add.ress externalip=your.ip.add.ress alias=A name for your node color=#000000 maxpendingchannels=5 bitcoin.mainnet=1 bitcoin.active=1 bitcoin.node=bitcoind bitcoind.rpcuser=bitcoind_rpc_user_string bitcoind.rpcpass=bitcoind_rpc_password_string bitcoind.zmqpath=tcp://127.0.0.1:18501
Make sure that
bitcoind.rpcpass match your environment.
4) Configure bitcoind
If you haven't done so, install bitcoindfirst. 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:
server=1 listen=1 daemon=1 txindex=1 rpcuser=bitcoind_rpc_user_string rpcpassword=bitcoind_rpc_password_string zmqpubrawblock=tcp://127.0.0.1:18501 zmqpubrawtx=tcp://127.0.0.1:18501
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:
sudo iptables save
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.