Tutorial of running lightning network in a distributed way
This tutorial is to show you how to set up lightning network in a distributed environment. In many cases, people are setting up bitcoin node and lightning network node in the cloud, and interacting with it from local computers. There is tutorial to show you how to set up everything in a local environment. But here we are talking about how to set up them in a distributed way.
There are a few of different implementations of lightning network and bitcoin. Here we are using lnd and btcd.
Step 1: set up btcd in cloud.
- Install btcd on a vm in any of the cloud providers: AWS, Digital Ocean or others. In our case, we use Digital Ocean. The public IP of the
btcd
vm is 142.93.13.155. - Started btcd by providing following parameters.
btcd --txindex --simnet --rpcuser=kek --rpcpass=kek --debuglevel=info --datadir=/data --logdir=/data --rpclisten=0.0.0.0
Step 2: set up lnd.
- Install lnd on another vm in the cloud.
- Started lnd by following command.
lnd --rpclisten=0.0.0.0:10001 --listen=0.0.0.0:10011 --restlisten=0.0.0.0:8001 --datadir=/k8s/data --logdir=/k8s/log --debuglevel=info --bitcoin.simnet --bitcoin.active --bitcoin.node=btcd --btcd.rpcuser=kek --btcd.rpcpass=kek --btcd.rpccert=/rpc/rpc.cert --btcd.rpchost=142.93.13.155
It needs following information for the lnd
to be able to connect with the btcd
node:
a. rpc user name and password: which is the same with the what is used for running btcd
.
b. rpc cert: which is generated on the btcd
machine. You can find in the btcd
vm under ~/.lnd
folder by default. You need to copy it to the lnd
machine.
c. rpc host address: which is the public ip address of the btcd
machine.
Step 3: set up lncli.
- Install
lncli
on the local machine. Here you just need to follow the same installation in step 2. - Following command below to create lightning wallet.
lncli --rpcserver=142.93.13.154:10001 -tlscertpath=/rpc/tls.cert create
3. Following command interact with lnd
in the cloud.
lncli --rpcserver=142.93.13.154:10001 -tslcertpath=/rpc/tls.cert -macaroonpath=/tmp/admin.macaroon getinfo
It needs following information to be able to connect with the lnd
node:
a. The public ip address for connect lnd
in the cloud. Here is 142.93.13.154.
b. Copy the tls.cert
from lnd
machine to local. The cert will be under ~/.lnd
by default.
c. After run the second command in step3, the admin.macaroon
will be created on the lnd
machine under <datadir>/chain/bitcoin/simnet/admin.macaroon
. In this case, it will be /k8s/data/chain/bitcoin/simnet/admin.macaroon
. You need to copy this file to local machine.
Summary
Following this tutorial, you will able to run lightning network in the distributed way. Please comment you have have any questions.