This article is part 1 of the new "Catching the BlockChain train" series: "The Lightning Network Rookie Guide".
Oh my, a new series! Tell me more!
After five episodes about IPFS, it's time for another exciting technology in blockchain world: Lightning Networks. From here on just
Lightning Network (singular, I'll explain why later) or
LN for short.
A quick test to see if you paid attention:
LN. Did you expand this in your mind to
Lightning Network? Well done, you passed!
BTW if you missed the episodes on IPFS, start here.
I like the idea to mix hands-on (playing with SW tools) with reading about and understanding the technology. This is reflected in the outline of this Rookie Guide*:
- Play with the LN as an end user: this episode.
- Understanding the basics of the LN.
- Preparation: set up a Bitcoin full-node and a local block explorer.
- LN hands-on: installing LN nodes, more wallets, apps, buying a t-shirt on mainnet, etc.
- Understanding the LN better: diving into the white paper and the spec.
*) If the term rookie offends you: I'm talking about myself of course. I'm figuring this all out while I write these posts turning myself from a rookie into a beginner.
Before we start, here's a glimpse of the genius of Satoshi Nakamoto: Satoshi's Vision! (Payment Channels / LN). That was in 2010!
We have a long way to go before we understand his specific statement:
nTimeLock does the reverse. It's an open transaction that can be replaced with new versions until the deadline. It can't be recorded until it locks. The highest version when the deadline hits gets recorded. It could be used, for example, to write an escrow transaction that will automatically permanently lock and go through unless it is revoked before the deadline. The feature isn't enabled or used yet, but the support is there so it could be implemented later.
but we'll get there, one step at the time.
Apparently, he was at it again in 2013: This email, composed in April of 2013 by Mike Hearn, quotes Satoshi talking about what is now known as the #LightningNetwork.
What's up with all the hype about the Lightning Network?
If you have been following Bitcoin tech, you are most likely aware of the Lightning Network. If not: it is a proposed solution to increase the scalability of the Bitcoin network by allowing "off-chain" transactions in a trustless way.
There has been a lot of talk about the LN lately, probably because there are a couple of implementations and it seems to work.
People are already using it on top of the main Bitcoin network. And three days ago the first LN node for mainnet was announced.
Here is a cool visualization of the current mainnet LN. When we are halfway this rookie guide I hope you and I to have our own node in there!
Now, why is the Lightning Network so exciting? I'm a fanboy for quite a while now, but this podcast with Elizabeth Stark and Andreas Antonopoulos got me really hooked: Let's Talk Bitcoin! #357 Real Lightning with Elizabeth Stark.
I encourage you to listen to the whole podcast, but if you don't, no worries, here are the points that stand out (IMHO at least):
- Scalability improvements for Bitcoin: speedy and low-fee transactions as Bitcoin was intended/advertised are now possible.
- Micropayments: for the first time in history there will be technology that makes small, cross-border, almost fee-free, payments possible.
- Interoperability: one LN for all blockchains. Just as the internet is a network of networks, we can see the LN as the blockchain of blockchains. Standardization is underway so that the different blockchains can work against a common interface. These specs are named BOLTs (like BIPs for Bitcoin).
- Cross chain swaps: this interoperability facilitates atomic swaps from, e.g., Bitcoin to Ethereum or any blockchain that interfaces with this overlaying LN. Genuinely decentralized exchanges will then be possible.
- Application layer: on top of the LN (layer two above Bitcoin e.a. which represent layer one) there is layer three which will be the application layer. Here is where the zapps or lapps live.
- Developer platform: the LN opens up a whole world of possibilities for developers. The LND implementation offers a gRPC interface that makes writing
(z|l)appseasier. We will dive into that later for sure!
- Developer community: there are 100s of developers active in this space, so let's hurry up and become one of them. They hang out in the Lightning Labs slack and get their documentation here.
Now if that doesn't get you excited... (it probably means you have a fun and meaningful life).
OK then, let's see how it looks like from the end-user perspective...
Lightning Network wallets
Before diving into the workings of the LN protocol and before setting up our own LN node let's try out some wallets that are available right now:
- Lighting Wallet
- Eclair Wallet
- Zap Desktop Wallet
- Lightning Desktop App
First get some testnet bitcoin
We use the wallets on the bitcoin testnet, so to play along you'll need some testnet bitcoin (tBTC). As in the old days for mainnet bitcoin, you can get them at a faucet.
This faucet and this one also worked for me. If you have trouble getting testnet coins, please tweet to me, and I'll send you some.
Note that testnet addresses have
2 as a prefix.
Testnet bitcoins haven't (and never will have) any value, but it still feels exciting to see a free 200.000.000 satoshis coming in :)
This Lightning Wallet is for Android only; you can download it here: Bitcoin + Lightning Wallet.
I love this wallet as it is a one-guy project in the person of Anton Kumaigorodskiy and it has some innovative features.
This wallet has an excellent online user manual, let's walk through it:
Setting up a Bitcoin wallet: this app is very convenient as it is an SPV Bitcoin node with a Lightning node built on top of it. Follow the instructions in the manual and send some testnet coins to your wallet. Note that you need a wait for the transaction to be confirmed a couple of times to proceed.
Next: Using the Lightning wallet.
Lightning tab and click
Open new channel. Now select a channel or search for one of the recommended channels by Anton. I picked
oh hi mark as it made me feel very welcome. Then fund the channel (hey, you can fund the channel with a sub-satoshi resolution!) and wait for two confirmations.
These confirmations can take a while as it is an actual bitcoin transaction. The amount you funded determines the maximum of the sum of the payments done through this channel. We'll dive into all this in the next episode of this guide.
As soon as we have an active payment channel, we can buy something.
My first purchase was an article at yalls.org for 100 test-satoshi, then left a comment for 21 test-satoshi. Micropayments are a reality!
I also bought a Blockaccino at starblocks. A few more places where you can spend tBTC here.
What happens here is that the payment is routed over a series of payment channels through a number of nodes. And all in a trustless way, with super low fees and very very fast. Pretty amazing no?
Watch the whole process in this Mobile Lightning wallet demo.
Anton also created another useful video: When Lightning goes wrong. It describes the various scenarios when channels are closed or when payments get stuck. These are the scenarios he describes:
A mutual (cooperative) closing transaction: both peers of the channel agree to close the channel, and the remaining balance is settled on the blockchain without any delays. Both peers need to be online for this to work.
Forced channel closing if a peer does not respond or becomes uncooperative. The peer that forces the channel to close is "punished" by a very long waiting time for their bitcoin to become spendable.
Your peer wants to steal from you by sending a previous commitment transaction to the blockchain. We see that the peer is punished for that and gets less than he would have had he played by the rules.
We'll find out in the next episode how all this is accomplished.
A last cool feature of this wallet consists of two parts: the app on your phone and a server that offloads some of the work from the mobile app. It's named Olympus, and there's a video about it here.
To receive a Lightning Network payment, we need another peer so let's move on to the next LN wallet...
HTLC.me is the easiest way to get started, as you don't need to install anything and it gives you a bit tBTC to play with.
From the user's perspective this is not a wallet, but a centralized front-end to a Lightning Network node. It keeps track of your balance, and you can access it by applying the recovery secret they provide the first time you activate your "wallet".
Anyway, now that I created a wallet on HTLC.me and funded it with some tBTC, I can use it to test the receiving function on Anton's Lightning Wallet:
From Anton's Lightning Wallet user guide:
Receiving Lightning funds
In order to receive Lightning payments, some conditions must be met:
Nothing can be received immediately after creating a new payment channel, as ‘room’ for incoming funds has to be made by spending some funds first. A payment channel can be thought of as a full bottle of water: in order to pour something in one first has to pour something out.
Each channel implicitly contains a reserve which is unspendable and typically takes about 1% of the channel’s capacity. You must spend that reserve before receiving is allowed. Unspendable channel reserve is the reason you see a negative receive limit when a new channel is full. It indicates how much you need to spend before anything can be received through the channel.
Every payment request is disposable, they can’t be fulfilled multiple times. So you will need to issue a new individual payment request for every incoming payment you wish to receive.
Your Lightning wallet needs to be online in order to receive funds.
Next to that, there is also a risk receiving payments on a mobile app that is not always online. The peer can attempt to steal from you by sending a previous commitment transaction. Your LN client can only correct this if it is online at least once per day.
After making some space in the channel from my mobile app, I gave it a shot. Although the steps are very smooth, the actual payment failed as HTLC.me couldn't establish a connection to my mobile wallet.
Let's try again with another wallet!
The Eclair wallet is also for Android only. It was announced in this blog post.
It works more or less the same as Anton's Lightning Wallet. One difference is that it doesn't allow receiving tBTC as explained in the announcement above.
The Eclair Wallet exposes some of the technical details like the Node id (Lightning Network's public identifier) of the wallet and the connected peers. Node addresses have the form of
Speaking of peers, the Eclair wallet allows connecting to multiple peers (aka more than one payment channel). If you know the Node id you can look it up in this brilliant explorer: https://explorer.acinq.co/#/n/03dc39d7f43720c2c0f86778dfd2a77049fa4a44b4f0a8afb62f3921567de41375.
From the wallet, you can scan that Node id and add it as another peer.
Let me sit down a bit to let this sink in... It is a cliche, but we are living in the future. Visa et al. should be scared.
Now, let's try again if we can receive with Anton's Lightning Wallet. I have both wallets connected to the same node to make it a bit easier (is it?). Unfortunately, we have no influence which channel the Eclair wallet uses.
A little while later I wake up in the now: one forever pending payment and another one failed. Visa can breath normal again.
Let's try with another wallet, maybe we have more luck there.
Zap Desktop Wallet
The Zap wallet is a different beast; it uses a full lnd node.
This wallet was first announced in this article: Announcing Zap: A Lightning Network Wallet. It has an embedded video with a walk-through that gives a good idea how it all works. But the better option is to download the wallet and play along! (BTW be warned this app is not ready for real use, it uses all CPU now and then, so only proceed if you like the sound of your computer's fans).
Download the latest release for your platform here: releases.
When running it the first time it takes a long time before you can use it. While it syncs, you can watch a couple of video's: Zap Lightning Network Wallet Tutorial.
I find this wallet not as intuitive as the other ones I played with, but it compensates this with the fact it is powered by a full lightning node. That hopefully means we can finally see how receiving tBTC works.
Another try to pay from Zap to Anton's app failed again, and payments to the Zap wallet from either mobile app also resulted in a
RouteNotFound. Not sure what is going on here, but receiving money is harder than spending it, just like in real life.
Let's move on to our last wallet...
Lightning Desktop App
The latest release of this wallet (still massively in development) can be downloaded here.
It was announced here: Announcing Our Lightning Desktop App, Now Available for Testing.
Unfortunately, I couldn't get it to work on my Mac. I created an issue, so when things get fixed (or they point me out what is wrong on my side) I'll update this article.
Making payments is unreal, fast and cheap!
Adding a peer node by reading a QR-code on the Lightning Network Explorer is like magic!
Receiving payments works very smooth if it worked... All my attempts failed, but OTOH, wallets that are not always online shouldn't receive payments in the first place. We have full nodes running on a server for that. Soon to be seen on this blog!
Of all the wallets both mobile wallets are my favorite, as it is more natural to pay with a QR scan from your phone than copy-pasting payment requests.
The next episode will be a bit less hands-on. I will dive deeper into the LN protocol, and hopefully, I can share that with you in an easy to understand way.