Bitcoin Lightning is a system that uses custom Bitcoin transactions to move assets quickly outside of the regular blockchain process. In this regard, Lightning is similar to the Tor Network where it uses TCP/IP as its backbone when routing anonymous connections. Bitcoin allows you to easily exchange money over the Internet without a central authority. Every transaction you make is direct to the payee, and you distribute it over the entire network.
Why Is Bitcoin Slow?
As a result, any payment that you make within Bitcoin takes time to complete and confirm. For example, a regular Bitcoin transaction normally takes 10 to 30 minutes to clear.
How Does the Lightning Network Work?
At its core, Lightning works by creating an “on-chain” payment that parks an amount of Bitcoin to your node. Lightning then uses your parked Bitcoin to create a channel between other Lightning nodes. This allows you to create additional “off-chain” payments through Lightning that do not need to clear in the blockchain, significantly reducing the payment time between two users. For example, a regular Lightning transaction only takes about a second to clear.
Setting Up Your Own Bitcoin Lightning Node
To get started with Lightning, it’s good to have your own personal node. Similar to setting up a Bitcoin node, a Lightning node allows you to have full control over your transactions in its network. To start the installation, you need to have a number of resources available and ready:
Machine with a decent amount of storage and memory. In my case, I am using an old Dell Optiplex desktop with 1TB of storage and 2GB of RAM.Constant Internet connection, as a Lightning node needs to regularly communicate with other nodes to maintain its state.Small amount of Bitcoin that you can use to “fund” your Lightning node.
Knowing these factors, this tutorial focuses on installing c-lightning to an Ubuntu 22.04.1 LTS machine.
Obtaining the Dependencies
The first step in installing c-lightning is to create a new user account to ensure that any files and settings for your node will be separated from your main user: Switch to this new user by running: su lightning, then add a third-party repository that will contain all the programs for c-lightning to work: Install the node’s dependencies:
Setting Up a Simple Bitcoin Node
From here, you need to install and configure a simple Bitcoin node. As discussed above, Lightning is an overlay network that works by using custom Bitcoin transactions to create “fund channels.” To create these channels, your Lightning node needs to run alongside a simple Bitcoin node that can be installed by running the following command: Create a symbolic link between your root “snap” directory and “bin” folder: Start the Initial Block Download for your Bitcoin node: This command will send the node to the background to download and verify the entire Bitcoin blockchain. You can check its progress by running the following command: It is important to note that this process can take between a few hours and a few days. For example, my Dell Optiplex desktop took 5 days to fully synchronize with the Bitcoin network.
Configuring Your Simple Bitcoin Node
Once your node is in sync with the network, make sure it is compatible with Lightning by first stopping the Bitcoin node: Edit its configuration file under “/etc/bitcoin.conf”: Disable two options: walletbroadcast and prune. The first option tells your Bitcoin node to only use its data with Lightning, and the second option ensures that you are saving the entire blockchain to your hard drive. Restart your Bitcoin node by running the following command:
Starting Up Your Bitcoin Lightning Node
Start your Lightning node by running the following command: This command will send the node to the background and create its configuration files under “/home/$USER/.lightning.” Test whether your Lightning node is running properly with this command:
Finalizing Your Bitcoin Lightning Node
With c-lightning running, you can finalize your node by creating the “fund channels” between different Lightning peers. As discussed above, a “fund channel” is a custom Bitcoin transaction that allows you to move your Bitcoin without committing to the blockchain. To create this, first “deposit” Bitcoin to your Lightning node by generating a receiving address for your node with the following command: Go to an external wallet and send Bitcoin to that receiving address. In my case, I will send 0.00050000 BTC using my Bitcoin Core wallet. Once the transaction is in the blockchain, your Lightning node will automatically update its fund balance. View this by running the following command:
Peering With Remote Bitcoin Lightning Nodes
Start to connect your node to its peers in the network to allow you to send and receive Bitcoin through Lightning. To start, find both its public key and IP address. Similar to using PGP Encryption, this allows you to connect and verify a node’s authenticity through public-key cryptography. One of the most common tools for doing this is 1ML: a website that lists all the active Lightning nodes in the network. Once you have an active node, use the lightning-connect command to establish a peer request. For example, this command will peer my node to ACINQ:
The first value indicates the slot number that you want to assign to the current peer. For this node, I am using slot 1.The second value is the remote node’s public key. In this case, I am using ACINQ’s public key.The third value is the remote node’s public IP address.
To finalize the request, send some of your node’s Bitcoin balance to the remote node to create a “fund channel” between you and a peering node. For example, this command will create a “fund channel” for 0.00030000 BTC to the first peer in my list:
Sending and Receiving Lightning Payments
With an active “fund channel” running, use your node to send and receive payments. By default, Lightning uses the BOLT11 format that starts with “lnbc” to differentiate it from Bitcoin. To send Bitcoin through Lightning, you must know the BOLT11 address of your recipient. For example, the following command sends 0.00005000 BTC to a remote address: You can also receive Bitcoin through Lightning using the invoice command and specify the exact amount of Bitcoin you want to receive. For example, this command creates an invoice for 0.00010000 BTC: Image Credit: Unsplash and Wikimedia Commons. All alterations and screenshots by Ramces Red. One way to fix this issue is to increase the amount of peers and “fund channels” that your local node connects to. For example, having at least two to three active peers will allow you to connect to almost any Lightning user.