How to Set Up a Lightning Node, Connect to a Peer and Open a Channel (4/4)
Before you decide to run your own Lightning Node, please note that current lightning network is experimental and could contain critical bugs that result in loss of funds.
This article will go through the necessary steps needed to set up a Lightning Network (LN) node on Bitcoin mainnet using a Raspberry Pi. I will be using C- Lightning implementation. You can also access the full documentation here. There are also a few other implementations, including LND, Eclair.
If you DO NOT wish to run mainnet Lightning network, you can always play around on testnet.
Install C- Lightning
In order to install C-Lightning package, You need to get dependencies:
sudo apt-get update
sudo apt-get install -y \
autoconf automake build-essential git libtool libgmp-dev \
libsqlite3-dev python python3 net-tools zlib1g-dev
Clone lightning from Github:
git clone https://github.com/ElementsProject/lightning.git
Configure your Lightning Node
Write the following data to your lightning config file.
If you wish to configure your lightning node on testnet
Starting Lightning Node
In order to start mainnet
lightningd you will need to have a local
bitcoind node running in mainnet.
If you are only interested in running a local
bitcoind in testnet. In order to start testnet
lightning . You will need to have a local
bitcoind node running in testnet.
bitcoind -daemon -testnet
bitcoind has synchronised with the mainnet/testnet network.
You can start
lightningd mainnet with the following command:
lightningd/lightningd --network=bitcoin --log-level=debug
If you wish to run the
lightningd on testnet
lightningd/lightningd --network=testnet --log-level=debug
Connecting to A Remote Lightning Peer
After you have successfully started the Lightning Node, you need to connect to a peer and sync the channel graph.
The peer used is mine: (I took the node offline, will update once I get my node back online)
cli/lightning-cli connect 03e27ab204bb3a34afaa19abbee8cfe26e32789f6f9a47faae114af0f443af18d1 126.96.36.199 9735
You can also connect to Blockstream’s peer
cli/lightning-cli connect 02f6725f9c1c40333b67faea92fd211c183050f28df32cac3f9d69685fe9665432 188.8.131.52 9735
The graph syncs automatically.
Creating An Address To Fund In Order To Open A Channel
Opening a Lightning payment channel requires a funded UTXO. Generate a Bitcoin address with
lightning-cli to send some bitcoin to.
However, for some reasons my bitcoin wallet does not support transfer to the Bech32 address format.
I need to generate a Segwit Bitcoin address with
cli/lightning-cli newaddr p2sh-segwit
Send some bitcoin to that address, but be mindful that this is experimental software.
Confirming We Have Received The BTC
lightning-cli to check if our address is funded:
The output will show as below, the status will show as confirmed when the transaction has at least 6 confirmations in the blockchain.
Opening A Channel With The Peer We Connected To Earlier
To open a payment channel, find the node’s pubkey or id (in this case, mine) and then use
lightning-cli to initiate opening the channel:
Copy that id and fund the channel with some number of satoshis:
amount_in_satoshi with the amount you are willing to fund to this channel e.g. If you want to fund 0.001 BTC, you need to replace
amount_in_satoshi with 100000 (1 BTC= 100,000,000 Satoshi)
cli/lightning-cli fundchannel 03e27ab204bb3a34afaa19abbee8cfe26e32789f6f9a47faae114af0f443af18d1 amount_in_satoshi
You can also fund a channel to Blockstream
cli/lightning-cli fundchannel 02f6725f9c1c40333b67faea92fd211c183050f28df32cac3f9d69685fe9665432
Confirming We Have Opened A Channel
Three confirmations are required for opening a channel. Once the funding transaction has three confirms, use
lightning-cli to list our new payment channel.
Welcome to the fam! You have now successfully setup a Bitcoin Lightning Node on mainnet.
Explore Bitcoin Lightning Network
I used the following explorer and resources to identify nodes’ address to connect to.
Bitcoin Lightning Network Testnet Explorer
Lightning Network Explorer (TESTNET)
Displays the Lightning Network nodes and channels on a map.