Setting up Lightning Network [2/3] – Set up your lnd node

Once you have set up your bitcoin node you can start setting up your lightning node. We will install lnd.

lnd is written in go. First we install the go compiler.

mkdir -p $HOME/src
cd $HOME/src
git clone https://go.googlesource.com/go
cd go
git checkout go1.12
cd src
./all.bash

add the following to your $HOME/.bashrc
export $GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin/:$HOME/src/go/bin

. $HOME/.bashrc

Once go is working we install lnd

go get -d github.com/lightningnetwork/lnd
cd $GOPATH/src/github.com/lightningnetwork/lnd
make && make install
make check

In order for lnd to communicate with your bitcoind process you need to configure zmq in your bitcoin.conf (if you followed my previous post you will have compiled bitcoind with zmq support).

cat >>/opt/bitcoin-data/bitcoin.conf
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
Ctrl-C

Create a directory and config file for lnd

mkdir -p /opt/lnd-data/
cp $HOME/go/src/github.com/lightningnetwork/lnd/sample-lnd.conf /opt/lnd-data/lnd.conf

These are some important variables to set up in your lnd.conf

[Application Options]
 datadir=/opt/lnd-data/
 logdir=/opt/lnd-data/logs
 maxlogfiles=3
 maxlogfilesize=10
 tlscertpath=/opt/lnd-data/tls.cert
 tlskeypath=/opt/lnd-data/tls.key
 no-macaroons=true
 nat=true
 alias=Rogeman
 color=#ab33ff
[Bitcoin]
bitcoin.active=1
bitcoin.testnet=1
bitcoin.node=bitcoind
[Bitcoind]
 bitcoind.rpchost=localhost
 bitcoind.rpcuser=roge
 bitcoind.rpcpass=34ZofsEbG95rWITDv8w03crrzIYBioGAKfMqDq1yY1A=
 bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
 bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333

Start your bitcoind and lnd nodes.

bitcoind --datadir=/opt/bitcoin-data/ -rpcuser=roge -rpcpassword=34ZofsEbG95rWITDv8w03crrzIYBioGAKfMqDq1yY1A=
lnd --configfile=/opt/lnd-data/lnd.conf

Now that your lnd node is running you need to create a wallet. It will ask you for a wallet password and a seed mnemonic passphrase. Write these down on paper and keep that paper safe.

 lncli --lnddir /opt/lnd-data/ --no-macaroons create

Create a new address so you can send some bitcoin to your lnd wallet

lncli --lnddir /disco-dos/lnd-data-mainnet/ --no-macaroons newaddress np2wkh
{
    "address": "3HUMZ7NVBQQqNHSnnj7dwS929YBUHTQoqu"
}

now send some satoshis (1 satoshi=1/100.000.000 btc, as of now 1 satoshi=0.00003 Euro) to your lnd wallet

bitcoin-cli -datadir=/opt/bitcoin-data -rpcuser=roge -rpcpassword=34ZofsEbG95rWITDv8w03crrzIYBioGAKfMqDq1yY1A= sendtoaddress 3HUMZ7NVBQQqNHSnnj7dwS929YBUHTQoqu 0.001

if you are on testnet you can get some free satoshis (a.k.a. sats) by googling lightning network testnet faucet (here’s one). Once you have sent some money to your lnd wallet you can check your balance.

lncli --lnddir /opt/lnd-data/ --no-macaroons wallletbalance
{
    "total_balance": "242539",
    "confirmed_balance": "242539",
    "unconfirmed_balance": "0"
}

lighning network is a mesh of point to point nodes, so let’s connect to some nodes in the network. You can find nodes to connect to here https://1ml.com for mainnet and https://1ml.com/testnet/ for testnet.

For example, let’s connect to 0232e20e7b68b9b673fb25f48322b151a93186bffe4550045040673797ceca43cf@178.128.202.182:9735

lncli --lnddir /opt/lnd-data/ --no-macaroons connect 0232e20e7b68b9b673fb25f48322b151a93186bffe4550045040673797ceca43cf@178.128.202.182:9735

We can check all the peers we are connected to

lncli --lnddir /opt/lnd-data/ --no-macaroons listpeers

let’s open a channel for 100000 sats

lncli --lnddir /opt/lnd-data/ --no-macaroons openchannel 0232e20e7b68b9b673fb25f48322b151a93186bffe4550045040673797ceca43cf 100000

now we can route payments through this node to any node in the lightning network. For example if you live in USA you can order a dominoes pizza. Let’s draw in satoshis.place my twitter handle (@Rogeman) (all-in cost 7675 sats, or 0,25 Euro. Totally worth it! :D)

lncli --lnddir /opt/lnd-data/ --no-macaroons sendpayment --pay_req=lnbc75970n1pw8s4uzpp5gl4mvj9mcnyz4ehvjhnceyxvdecn60gjny95qq02wd80rj5eywdsdzy2pshjmt9de6zqen0wgsrwdfexus8q6tcv4k8xgrpwss8xct5daeks6tn9ecxcctrv5hqxqzjccqp2rzjqtkru466qeqlcsvm0ql5338v8geseqxa6x9kcnkqcef6p7msfhmw6zrut5qqpjsqqyqqqqlgqqqqqeqqjq5f54fkcjjspqc4j403l067q3ujcet6lvzm98jyqwkujzz43gufyq8cxumdrsrqxlkrrrpv2yj3ejn2syqwyx2jzfmz5ls0ym87sny7gpuvsj4l
Description: Payment for 7597 pixels at satoshis.place.
Amount (in satoshis): 7597
Destination: 024655b768ef40951b20053a5c4b951606d4d86085d51238f2c67c7dec29c792ca
Confirm payment (yes/no): yes
{
        "payment_error": "",
        "payment_preimage": "cfc4a1f1974aeb3be9f7c29fc03d85757fe9f3f675ee2fd93d5b3a2b01fb5a97",
        "payment_route": {
                "total_time_lock": 565405,
                "total_fees": 78,
                "total_amt": 7675,
                "hops": [
                        {
                                "chan_id": 621324125340041216,
                                "chan_capacity": 100000,
                                "amt_to_forward": 7598,
                                "fee": 76,
                                "expiry": 565391,
                                "amt_to_forward_msat": 7598196,
                                "fee_msat": 76981,
                                "pub_key": "0232e20e7b68b9b673fb25f48322b151a93186bffe4550045040673797ceca43cf"
                        },
                        {
                                "chan_id": 606036515588079617,
                                "chan_capacity": 1259649,
                                "amt_to_forward": 7598,
                                "expiry": 565247,
                                "amt_to_forward_msat": 7598007,
                                "fee_msat": 189,
                                "pub_key": "0395033b252c6f40e3756984162d68174e2bd8060a129c0d3462a9370471c6d28f"
                        },
                        {
                                "chan_id": 621250457985744896,
                                "chan_capacity": 40000,
                                "amt_to_forward": 7597,
                                "fee": 1,
                                "expiry": 565103,
                                "amt_to_forward_msat": 7597000,
                                "fee_msat": 1007,
                                "pub_key": "0371513dee8725b7c4eae15c7a350e6559c5aa9c007d7d27ea436571acf6927e75"
                        },
                        {
                                "chan_id": 621254856070397952,
                                "chan_capacity": 500000,
                                "amt_to_forward": 7597,
                                "expiry": 565103,
                                "amt_to_forward_msat": 7597000,
                                "pub_key": "024655b768ef40951b20053a5c4b951606d4d86085d51238f2c67c7dec29c792ca"
                        }
                ],
                "total_fees_msat": 78177,
                "total_amt_msat": 7675177
        }
}