mirror of
https://github.com/lnbook/lnbook
synced 2024-11-01 03:20:53 +00:00
249 lines
20 KiB
Plaintext
249 lines
20 KiB
Plaintext
[[getting-started]]
|
|
== Getting Started
|
|
|
|
In this chapter, we will choose software to demonstrate the Lightning Network and learn by example. We will examine the choices of two users who represent a common use-case for the Lightning Network.
|
|
|
|
Alice, a coffee shop customer, will be using a LN wallet on her mobile device to buy coffee from Bob's Cafe. Bob, a merchant, will be using a LN node and wallet to run a point-of-sale system at his cafe so he can accept payment over the Lightning Network.
|
|
|
|
=== Lightning Nodes
|
|
|
|
The Lightning Network is accessed via software applications that can speak the Lightning Network protocol. A _Lightning Network Node_ (or simply "node") is a software application that communicates on a peer-to-peer basis with other LN nodes, forming the Lightning _Network_ itself. Nodes also include "wallet" functionality, so they can send and receive payments over the Lightning Network and on the Bitcoin network.
|
|
|
|
Lightning network nodes also need access to the Bitcoin blockchain (or other blockchains for other cryptocurrencies). Users have the highest degree of control by running their own Bitcoin node and LN node.
|
|
|
|
However, LN nodes can also use a lightweight Bitcoin client (commonly referred to as Simplified Payment Verification (SPV)) to partially validate the correctness of their blockchain.
|
|
|
|
=== Lightning Wallets
|
|
|
|
The term "Lightning Wallet" is somewhat ambiguous, as it can describe a broad variety of components combined with some user interface. The most common components of lightning wallet software include:
|
|
|
|
* A keystore that securely holds secrets, such as private keys.
|
|
* A Lightning Network node that communicates on the Peer-to-Peer network, as described previously.
|
|
* A Bitcoin node that stores blockchain data and communicates with other Bitcoin nodes.
|
|
* A channel data store with data about channels on the Lightning Network.
|
|
* A channel manager that can open and close Lightning Network channels.
|
|
* A path-finding system that can identify a path of connected channels from payment source to payment destination.
|
|
|
|
A lightning wallet may contain all of these functions, acting as a "full" wallet, with no reliance on any third-party services. Or, one or more of these components may rely (partially or entirely) on third-party services that mediate those functions.
|
|
|
|
A key distinction (pun intended), is whether the keystore function is internal or outsourced. In blockchains, control of keys determines custody of funds, as memorialized by the phrase "your keys, your coins; not your keys, not your coins". Any wallet that outsources management of keys is called a "custodial" wallet, because a third party (custodian) has control of the user's funds, not the user themselves. A "non-custodial" or "self-custody" wallet, by comparison, is one where the keystore is part of the wallet, and keys are controlled directly by the user.
|
|
|
|
Blockchains, especially open blockchains like Bitcoin, attempt to minimize or eliminate trust in third parties and empower users. This is often called a "trustless" model, though "trust-minimized" is a better term. In such systems, the user trusts the software rules, not third parties. Therefore, the issue of control over keys is a principal consideration when choosing a lightning wallet.
|
|
|
|
Every other component of a lightning wallet brings similar considerations of trust. If all the components are under the control of the user, then the amount of trust in third parties is minimized, bringing maximum power to the user. Of course, this is a direct tradeoff, as with that power comes the responsibility to manage complex software.
|
|
|
|
Every user must consider their own technical skills before deciding what type of lightning wallet to use. Those with strong technical skills should use a lightning wallet that puts all of the components under the direct control of the user. Those with less technical skill but a desire to control their funds, should choose a _non-custodial_ lightning wallet, even if some of the components (other than the keystore) rely on some trusted third parties.
|
|
|
|
Finally, those seeking simplicity and convenience, even at the expense of control and security, may choose a custodial lightning wallet. This is the least challenging option, but it _undermines the trust model of cryptocurrency_ and should, therefore, be considered only as a stepping stone towards more control and self-reliance.
|
|
|
|
In <<lnwallet-categories>> we see the three broad categories of lightning wallets and the relative degree of control they offer to the user.
|
|
|
|
[[lnwallet-categories]]
|
|
.Broad Categories of "LN Wallets"
|
|
|===
|
|
| Wallet Type | LN Node | Keystore/Custody | Technical Skill
|
|
| Full Node & Wallet | Full Node | Non-Custodial | High
|
|
| Non-Custodial Wallet | 3rd-party node | Non-Custodial | Medium
|
|
| Custodial Wallet | 3rd-party node | Custodial | Low
|
|
|===
|
|
|
|
|
|
Lightning wallets can be installed on a variety of devices, including laptops, servers, and mobile devices. To run an LN node and a Bitcoin node, you will need to use a server or desktop computer, as mobile devices and laptops are usually not powerful enough in terms of capacity, processing, battery life, and connectivity.
|
|
|
|
In <<lnwallet-examples>> we see some examples of currently popular LN node and wallet applications for different types of devices.
|
|
|
|
// TODO: Add a lot more wallet/node examples, confirm the details for correctness
|
|
[[lnwallet-examples]]
|
|
.Examples of Popular LN Wallets
|
|
|===
|
|
| Application | Device | LN Node | Bitcoin Node | Keystore
|
|
| lnd | Server | Full Node | Bitcoin Core/btcd | User Control
|
|
| c-lightning | Server | Full Node | Bitcoin Core | User Control
|
|
| Eclair Server | Server | Full Node | Bitcoin Core/Electrum | User Control
|
|
| Zap Desktop | Desktop | Full Node | Bitcoin Core/btcd | User Control
|
|
| Eclair Mobile | Mobile | Lightweight | Electrum | User Control
|
|
| Breez Wallet | Mobile | Full Node | Bitcoin Core/btcd | User Control
|
|
| Phoenix Wallet | Mobile | ?? | ?? | User Control
|
|
| Blue Wallet | Mobile | None | None | Custodial
|
|
|===
|
|
|
|
=== Balancing complexity and control
|
|
|
|
Lightning wallets have to strike a careful balance between complexity and user control. Those that give the user the most control over their funds, the highest degree of privacy and the greatest independence from third party services are necessarily more complex and difficult to operate. As the technology advances, some of these trade-offs will become less stark and users may be able to get more control without more complexity. However, for now, different companies and projects are exploring different positions along this control-complexity spectrum and hoping to find the "sweet spot" for the users they are targeting.
|
|
|
|
When selecting a wallet keep in mind that even if you don't see these trade-offs they still exist. For example, many wallets are attempting to remove the burden of channel management from users. To do so, they are introducing central "hub" nodes that their wallets all connect to automatically. While this trade-off simplifies the user interface and user experience, it introduces a Single Point of Failure (SPoF) and a potential privacy compromise, as these "hub nodes" become both indispensable and can see all the user's transactions.
|
|
|
|
In the next section we will introduce our first user and walk through their first LN wallet setup. We have chosen a wallet that is not as easy to use as some others currently available. This is because we want to show some of the underlying complexity and introduce some of the inner workings of the wallet during our example. You may find that your ideal wallet is further towards "ease of use", by accepting some of the control and privacy trade-offs. Or perhaps you are more of a "power user" and want to run your own LN and Bitcoin nodes as part of your wallet solution.
|
|
|
|
== Alice's First LN Wallet
|
|
|
|
Alice is a long time Bitcoin user. We first met Alice in Chapter 1 of _"Mastering Bitcoin"_ footnote:["Mastering Bitcoin 2nd Edition, Chapter 1" Andreas M. Antonopoulos (https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch01.asciidoc).], when she bought a cup of coffee from Bob's cafe, using a bitcoin transaction. Now, Alice is eager to learn about and experiment with the Lightning Network. First, she has to select an LN wallet that meets her needs.
|
|
|
|
Alice does not want to entrust custody of her bitcoin to third parties. She has learned enough about cryptocurrency to know how to use a wallet. She also wants a mobile wallet so that she can use it for small payments on-the-go, so she chooses the _Eclair_ wallet, a popular non-custodial mobile LN wallet.
|
|
|
|
=== Downloading and Installing an LN Wallet
|
|
|
|
When looking for a new cryptocurrency wallet, you must be careful to select a secure source for the software.
|
|
|
|
There are many fake wallet applications that steal your money, and some of these even find their way onto reputable and supposedly vetted software sites, like the Apple and Google application stores. Whether you are installing your first or your tenth wallet, always exercise extreme caution. A rogue app can not only steal money any money you entrust it with, it might also be able to steal keys and passwords from other applications by compromising your mobile device operating system.
|
|
|
|
[WARNING]
|
|
====
|
|
Always exercise great care when installing software on any device. There are many fake cryptocurrency wallets that will not only steal your money but might also compromise all other applications on your device.
|
|
====
|
|
|
|
Alice uses an Android device, and will use the Google Play Store to download and install the Eclair wallet.
|
|
|
|
Searching on Google Play, she finds an entry for "Eclair Mobile", as shown in <<eclair-playstore>>.
|
|
|
|
[[eclair-playstore]]
|
|
.Eclair Mobile in the Google Play Store
|
|
image:images/eclair-playstore.png["Eclair wallet in the Google Play Store"]
|
|
|
|
Alice notices a few different elements on this page, that help her ascertain that this is, most likely, the correct "Eclair Mobile" wallet she is looking for. Firstly, the organization "ACINQ" footnote:[ACINQ: Developers of the Eclair Mobile LN wallet (https://acinq.io/).] is listed as the developer of this mobile wallet, which Alice knows from her research is the correct developer. Secondly, the wallet has been installed "10,000+" times and has more than 320 positive reviews. It is unlikely this is a rogue app that has snuck into the Play Store. Satisfied by these findings, Alice installs the Eclair app on her mobile device.
|
|
|
|
=== Creating a New Wallet
|
|
|
|
When Alice opens the Eclair Mobile app for the first time, she is presented with a choice, to "Create a New Wallet" or to "Import an Existing Wallet". Alice will create a new wallet, but let's first discuss why these options are presented here and what it means to "import an existing wallet".
|
|
|
|
==== Responsibility with Key Custody
|
|
|
|
As we mentioned in the beginning of this section, Eclair is a _non-custodial_ wallet, meaning that Alice has sole custody of the keys used to control her bitcoin. This also means that Alice is responsible for protecting and backing up those keys. If Alice loses the keys, no one can help her recover the bitcoin and it will be lost forever.
|
|
|
|
[WARNING]
|
|
====
|
|
With the Eclair Mobile wallet, Alice has custody and control of the keys and therefore full responsibility to keep the keys safe and backed up. If she loses the keys, she loses the bitcoin and no one can help her recover from that loss!
|
|
====
|
|
|
|
==== Mnemonic Words
|
|
|
|
Similar to most Bitcoin wallets, Eclair Mobile provides a _mnemonic phrase_ for Alice to back up. The mnemonic phrase consists of 24 English words, selected randomly by the software, and used as the basis for the keys that are generated by the wallet. The mnemonic phrase can be used by Alice to restore all the transactions and funds in the Eclair Mobile wallet in the case of a loss, for example because of a lost mobile device, software bug, or memory corruption.
|
|
|
|
[TIP]
|
|
====
|
|
The _mnemonic phrase_ is often mistakenly called a "seed". In fact, a seed is constructed _from the mnemonic_ and is something different.
|
|
====
|
|
|
|
When Alice chooses to "Create a New Wallet", she will be shown a screen with her mnemonic phrase, which looks like the screenshot in <<eclair-mnemonic>>.
|
|
|
|
[[eclair-mnemonic]]
|
|
.Eclair Mobile: New Mnemonic Phrase
|
|
image:images/eclair-mnemonic.png["Eclair Mobile: New Mnemonic Phrase"]
|
|
|
|
In <<eclair-mnemonic>> we have purposely obscured part of the mnemonic phrase to prevent readers of this book from reusing the mnemonic.
|
|
|
|
[[mnemonic-storage]]
|
|
=== Storing the Mnemonic Safely
|
|
|
|
Alice needs to be careful to store the mnemonic phrase in a way that balances the need to prevent theft and accidental loss. The recommended way to properly balance these risks is to write two copies of the mnemonic phrase on paper, with each of the words numbered (the order matters!).
|
|
|
|
Once Alice has recorded the mnemonic phrase, after touching "OK GOT IT" on her screen she will be presented with a _quiz_ to make sure that she correctly recorded the mnemonic. The quiz will ask for three or four of the words at random. Alice wasn't expecting a quiz, but since she recorded the mnemonic correctly she passes without any difficulty.
|
|
|
|
Once Alice has recorded the mnemonic phrase, and passed the "quiz", she should store each copy in a separate secure location such as a locked desk drawer, or a fireproof safe.
|
|
|
|
[WARNING]
|
|
====
|
|
Never attempt a "DIY" security scheme that deviates in any way from the best practice recommendation in <<mnemonic-storage>>. Do not cut your mnemonic in half, make screenshots, store on USB drives or cloud drives, encrypt it, or try any other non-standard method. You will tip the balance in such a way as to risk permanent loss or theft. Many people have lost funds, not from theft, but because they tried a non-standard solution without having the expertise to balance the risks involved. The best practice recommendation is carefully balanced by experts and suitable for the vast majority of users.
|
|
====
|
|
|
|
After Alice initializes her Eclair Mobile wallet, she will see a brief tutorial which highlights the various elements of the user interface. We won't replicate the tutorial here, but we will explore all those elements as we follow Alice's attempt to buy a cup of coffee!
|
|
|
|
=== Loading Bitcoin Into the Wallet
|
|
|
|
Alice now has an LN wallet. But, it's empty! She now faces one of the more challenging aspects of this experiment: she has to find a way to acquire some bitcoin and load it onto her Eclair wallet.
|
|
|
|
==== Acquiring Bitcoin
|
|
|
|
There are several ways Alice can acquire bitcoin:
|
|
|
|
* She can exchange some of her national currency (eg. USD) at a crypto-currency exchange
|
|
* She can buy some from a friend, or an acquaintance from a Bitcoin Meetup, in exchange for cash
|
|
* She can find a _Bitcoin ATM_ in her area, which acts as a vending machine, selling bitcoin for cash
|
|
* She can offer her skills or a product she sells and accept payment in bitcoin
|
|
* She can ask her employer or clients to pay her in bitcoin
|
|
|
|
All these methods have varying degrees of difficulty and many will involve paying a fee. Some will also require Alice to provide identification documents to comply with local banking regulations.
|
|
|
|
However, with all these methods, Alice will be able to receive bitcoin directly into her Eclair wallet.
|
|
|
|
==== Receiving Bitcoin
|
|
|
|
For the purpose of our example, let's assume Alice has found a local Bitcoin ATM and has decided to buy some bitcoin in exchange for cash. An example of a Bitcoin ATM, one built by the Lamassu company, is shown in <<bitcoin-atm>>. A Bitcoin ATM like this one accepts national currency (cash) through a cash slot and send bitcoin to a Bitcoin Address scanned from a user's wallet using a built-in camera.
|
|
|
|
[[bitcoin-atm]]
|
|
.A Lamassu Bitcoin ATM
|
|
image:images/bitcoin-atm.png[]
|
|
|
|
To receive the bitcoin in her Eclair LN wallet, Alice will need to present a _Bitcoin Address_ from the Eclair LN wallet to the ATM. The ATM can then send Alice's newly acquired bitcoin to this bitcoin address.
|
|
|
|
On the Eclair wallet, to see a Bitcoin Address Alice must swipe to the left column titled "YOUR BITCOIN ADDRESS" (see <<eclair-receive>>), where she will see a square bardcode (called a _QR code_) and a string of letters and numbers below.
|
|
|
|
[[eclair-receive]]
|
|
.Alice's bitcoin address, shown in Eclair
|
|
image:images/eclair-receive.png[]
|
|
|
|
The QR code contains the same string of letters and numbers as shown below it, in an easy to scan format. This way, Alice doesn't have to type the Bitcoin Address. In the screenshot <<eclair-receive>>, we have purposely blurred both, to prevent readers from inadvertently sending bitcoin to this address.
|
|
|
|
[NOTE]
|
|
====
|
|
Both Bitcoin addresses and QR codes contain error detection information that prevents any typing or scanning errors from producing a "wrong" Bitcoin address. If there is a mistake in the address, any Bitcoin wallet will notice the error and refuse to accept the Bitcoin Address as valid.
|
|
====
|
|
|
|
Alice can take her mobile device to the ATM and show it to the built-in camera, as shown in <<bitcoin-atm-receive>>. After inserting some cash into the slot, she will receive bitcoin in Eclair!
|
|
|
|
[[bitcoin-atm-receive]]
|
|
.Bitcoin ATM scans the QR code
|
|
image:images/bitcoin-atm-receive.png[]
|
|
|
|
Alice will see the transaction from the ATM in the "TRANSACTION HISTORY" tab of the Eclair wallet. While the bitcoin transaction will be detected by Eclair in just a few seconds, it will take approximately one hour for the bitcoin transaction to be "confirmed" on the Bitcoin Blockchain. As you can see in <<eclair-tx1>>, Alice's Eclair wallet shows "6+ conf" below the transaction, indicating that the transaction has received the required six confirmations and her funds are ready to use.
|
|
|
|
[[eclair-tx1]]
|
|
.Alice receives bitcoin
|
|
image:images/eclair-tx1-btc.png[]
|
|
|
|
=== From Bitcoin to Lightning Network
|
|
|
|
Alice's bitcoin is now controlled by her Eclair wallet and has been recorded on the Bitcoin Blockchain. At this point, Alice's bitcoin is "on-chain", meaning that she has completed a regular Bitcoin transaction, broadcast to the entire Bitcoin network, verified by all Bitcoin nodes and "mined" (recorded) onto the Bitcoin blockchain.
|
|
|
|
So far, the Eclair Mobile wallet has behaved only as a Bitcoin wallet and Alice hasn't used the Lightning Network features of Eclair. As is the case with many LN wallets, Eclair "straddles" Bitcoin and the Lightning Network by acting as both a Bitcoin wallet and a Lightning wallet.
|
|
|
|
Now, Alice is ready to start using the Lightning Network by taking her bitcoin "off-chain", so she can take advantage of the fast, cheap and private payments that LN offers.
|
|
|
|
==== Opening a Lightning Network Channel
|
|
|
|
Swiping right, Alice accesses the "LIGHTNING CHANNELS" section of Eclair. Here she can manage the LN channels that will connect her wallet to the Lightning Network.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////
|
|
[[getting_first_bitcoin]]
|
|
=== Getting Your First bitcoin on the Lightning Network
|
|
|
|
* Trade fiat for bitcoin (as in Mastering Bitcoin)
|
|
|
|
[[using_own_bitcoin]]
|
|
=== Process for people who already own bitcoin ====
|
|
|
|
* send bitcoin to lightning wallet (1 onchain transaction - soon nodes / wallets may support funding a channel directly without sending bitcoin to the lightning network wallet first)
|
|
* find a node to open a channel with (Node explorer / Autopilots / ...)
|
|
* open a connection
|
|
* open a channel
|
|
* wait confirmations for the channel to become operational
|
|
|
|
|
|
[[sending_receiving]]
|
|
=== Sending and Receiving Bitcoin on the Lightning Network
|
|
* have the person who helps onbording open a payment channel (As complex as a bitcoin transaction)
|
|
* showcase how the funds now can be send back and forth
|
|
** create invoice
|
|
** decode invoice (do always before paying!)
|
|
** pay an invoice
|
|
* showcase how an arbitrary invoice can be paid e.g. https://voting.ln.rene-pickhardt.de
|
|
|
|
////
|
|
|
|
== Conclusion
|