What Is the Bitcoin Lightning Network: how to use it and why we need it
Bitcoin has been created as a peer-to-peer electronic cash. However, the way the protocol was designed makes it hard to use it for everyday spending: every transaction needs significant time to finalize, compared to fiat payment networks like Visa and Mastercard. In 2016, developers Joseph Poon and Thaddeus Dryja suggested a solution that would make bitcoin significantly faster – the Lightning network protocol.
Transactions are getting written into the bitcoin blockchain in blocks, which are added one by one every 10 minutes, making the overall speed of the bitcoin network around 7-10 transactions per second. And it takes six blocks, or about an hour, for the transaction to be considered irreversible, i.e., too hard for malicious actors to roll back by compromising the blockchain – in a hypothetical scenario where someone would try to do that.
The idea of Bitcoin Lightning is that not every transaction needs to happen on-chain. Finalization time and bitcoin network fees make small transactions impractical – but you can build a virtual second layer above the bitcoin blockchain where people can exchange small amounts and settle on-chain every once in a while.
What is Bitcoin Lightning?
The concept behind the Bitcoin Lightning Network, proposed by Poon and Dryja, implemented by Lightning Labs in 2018, moves small peer-to-peer transactions from the main bitcoin blockchain to Layer 2. Users open payment channels between each other by locking funds in 2-of-2 multisigs. How 2-of-2 multisig works? These multisigs are smart contracts that create temporary ledgers of transactions which are not written into the blockchain but still verified and secured by the bitcoin cryptography.
Users can transact between each other multiple times, but on-chain, only two transactions are visible: the one creating the payment channel and the one returning users their funds according to the latest state of the payment channel. The changing state of the bitcoin network works as a clock here for transactions to complete or expire.
But there is more: users can transact not only with the people they opened mutual payment channels with – they can connect to the global network, which currently consists of 17,438 nodes worldwide, with over 5,000 BTC locked 41,109 channels. This network allows users to send funds to wallets that they haven’t opened channels with, as satoshis bounce through other nodes and channels until they reach the receiving user. Poon and Dryja wrote that “requiring everyone to create channels with everyone else does not solve the scalability problem” for bitcoin, but connecting channels into a network available to all participants does.
This mechanism allows using bitcoin for small transactions without clogging the bitcoin network and making it hard to use: when too many transactions are waiting for confirmation, transaction fees get higher and users have to wait longer for their payments to go through. But keeping small transactions off-chain takes the pressure off the network.
How does the Bitcoin lightning network work?
Understanding how the Lightning Network works helps explain why it can process transactions faster than the Bitcoin network.
For a full description of Lightning’s technical details, check the white paper by Poon and Dryja – we’ll give a high-level overview for basic understanding here.
To open a Lightning Network channel and connect to the Lightning network, you need a Lightning node – just like you need a bitcoin node to participate in the bitcoin network. You can host your bitcoin and Lightning nodes on the same hardware or have separate devices, depending on the hardware you use and your own preferences.
A Lightning funding transaction locks your funds in a P2WSH (Pay-to-Witness-Script-Hash) multisign address. It starts with a funding transaction, when two participants create a 2-of-2 multisig with each of them controlling one key. This funding transaction gets broadcasted onto the bitcoin blockchain.
After that, both participants sign an initial commitment transaction, spending from the 2-of-2 output of the funding transaction. After that, they can perform more commitment transactions, each of which updates the state of the payment channel without broadcasting it to the bitcoin blockchain.
When participants decide to close the channel, they make a final settlement transaction, which gets confirmed on the blockchain. Alternatively, one party can close the channel by broadcasting the latest commitment transaction.
How to use Bitcoin lightning network?
You can use Lightning network payments for a number of things. First of all, you can pay people faster and more privately via Lightning network: unlike on-chain bitcoin transactions, Lightning transactions, especially the ones that go through multiple hops, do not connect the wallets of sender and recipient on the public blockchain for everyone to see.
“I pay for my VPN via lightning. I'd just prefer that my credit card company doesn't know who my VPN supplier is. And if I want to send cash to someone, I use lightning and that person doesn't know where it came from,” says this Reddit user.
To simplify using Lightning for people who don’t want the pain of setting up and maintaining their own nodes, popular wallets support their own payment channels – this is more convenient, but practically amounts to using centralized custodians, so keep that in mind.
You can buy gift cards via services like Bitrefill or Cryptorefills using Lightning, which includes subscriptions to VPNs, streaming and gaming services, gift cards for fashion brands and retail chains, electronics stores, and pre-paid digital debit cards. Usually, popular Lightning wallets offer built-in integrations allowing you to buy gift cards. You can also tip your favorite bloggers on Nostr using Lightning for the so-called Zaps. Bitcoiners in Canada can even pay utility bills with Lightning via Bitcoin well.
If you’re a business owner, Lightning may be a good payment option for your crypto-savvy customers. Theoretically, running your own Lightning node and serving as a relay for other people’s transactions can also bring you some income in the form of fees, but in practice, it requires significant investment both in terms of money and time – if you’re curious about this aspect, take a look at this discussion on Reddit.
Issues with Lightning
As a new and complex technology, the Bitcoin Lightning network has some risks, which is good to keep in mind – and use it carefully, like any nascent technology.
There are certain scenarios in which malicious actors can attack Lightning nodes and make users lose funds – rather than bugs in the code, such attacks would be results of complex technical and social mechanics that can come into play when multiple people are exchanging money in a decentralized way. The list of such possible attacks includes:
- mass exit attack, in which multiple nodes collude and either go offline, locking the funds in channels for long periods of time, or steal funds by submitting closing transactions that settle channels using expired protocol states;
- transaction-relay jamming attacks: an attacker operating a node could break the chain of hops by replacing a valid transaction with a malicious one using a higher fee – as a result, an honest node operator could lose funds;
- time-dilation attack, in which an attacker manipulates the time locks to delay transaction settlements, disrupting the whole network.
These are purely theoretical scenarios – at least until now, there have been no known cases of such attacks.
But there have been attacks exploiting bugs in Lightning clients. For example, in November 2021, a hacker exploited a bitcoin tipping bot for Telegram and stole 0.14 BTC, or about $9,480, taking advantage of a bug in the Éclair client by ACINQ. In October 2022, a bug in Lightning Labs’ Bitcoin full node implementation, BTCD, prevented users from creating and closing channels until it was fixed.
With all that said – have fun with Lightning but use it with caution! Bitcoin keeps evolving, new technologies constantly emerge on top of it, and that’s what makes it exciting.