Intro to Lightning Network and Tutorial


Introduction to Lightning Network and Tutorial


The lightning network is software that uses the bitcoin blockchain and network to enable fast and cheap off-chain transactions. It was developed as a scaling solution to reduce the transaction (tx) backlog and reduce fees by moving the majority of transactions off of the blockchain. Lightning was developed and implemented by the bitcoin core team, after bitcoin forked to add segrated witness (segwit). Segwit was not the only way to enable lightning payments, but was the chosen solution at the time.

With lightning, a channel can be opened between two bitcoin wallets with a single on-chain transaction. Funds are committed to the channel, then they can be moved back and forth between the two wallets until one of the wallets wishes to close the channel. Closing the channel requires a second on-chain transaction. The end result is that many payments will have been facilitated between two parties, while only requiring two on-chain transactions.

It’s easiest to imagine a lightning channel as an abacus (a manual calculator used since ancient times). After two wallets connect over the lightning network, a channel can be opened between them. One side funds the channel with bitcoin from its wallet, choosing to commit funds to one/both sides of the channel. Like an abacus, the funds can only be moved back and forth between the two wallets (like the beads moving back and forth on the abacus rod).

Another useful analogy is a bar tab; a patron ordering drinks at a bar can choose to:

a. pay for each drink when it’s ordered (akin to making multiple on-chain txs) or

b. open a tab and order drinks over time, then pay at the end*

* lightning actually requires an on-chain tx to open a channel, then a second on-chain tx to close it.

The “network” part of lightning is in the way these channels connect, each serving as a link in a chain (another analogy). This allows one wallet to pay another wallet that it is not directly connected with, making a payment multiple channel hops away. Further, each node that is “hopped through” receives a small fee (paid by the sender) for helping to propogate the transaction.

You can try out the lightning network on the testnet and/or mainnet, and connect to the anypay node by following the steps below:

 


Testnet Tutorial


[Mobile Wallet]

 

1. Download Eclair Wallet Testnet (currently available for Android only)*

* Eclair Wallet installation tutorial (with pictures): https://steemit.com/cryptocurrency/@chronicusprime/how-to-try-out-lightning-network-using-eclair-app-for-android

2. Get coins sent to your bitcoin address by requesting some from a faucet such as:

https://testnet.manu.backend.hamburg/faucet

3. Scan the anypay node uris QR code below (or copy/paste the node uris), and fund the channel with at least .001 btc (=100,000 satoshis)

025351225e1aac4ef3ce8084d3160be79a26bf9df92e62fd5282b7821eb6e4e45c@52.14.230.25:9735

4. After the transaction has 6 confirmations, you will have successfully opened a lightning channel with the anypay testnet node!

(You can look up your tx by using a block explorer such as https://live.blockcypher.com/btc-testnet/)


[Desktop Terminal Wallet]

 

1. Install lightning network on your computer:

normal install: https://dev.lightning.community/guides/installation/

docker install: https://dev.lightning.community/guides/docker/

2. Connect to the lightning faucet node (https://faucet.lightning.community/) by issuing terminal command:

lncli connect 0270685ca81a8e4d4d01beec5781f4cc924684072ae52c507f8ebe9daf0caaab7b@159.203.125.125

3. Request channel to be opened with lightning faucet at https://faucet.lightning.community/ (prompts below)

a. Target Node:

Paste your node id in the “Target Node” prompt

b. Channel Amount (in satoshis):

Mininum: 100000

Maximum: 16000000

c. Initial Balance (in satoshis):

Needs to be ~10000 less than Channel Amount (due to opening + closing tx fees)

4. Connect to the anypay node by issuing terminal command:

lncli connect 025351225e1aac4ef3ce8084d3160be79a26bf9df92e62fd5282b7821eb6e4e45c@52.14.230.25:9735

5. Open a channel with anypay:

lncli openchannel –node_key=025351225e1aac4ef3ce8084d3160be79a26bf9df92e62fd5282b7821eb6e4e45c –local_amt=100000 –conf_target=1

Note: The –conf_target=1 flag is optional, but was included to allow the client to automatically calculate fees to help get the tx into the next block.

6. After the transaction has 6 confirmations, you will have successfully opened a lightning channel with the anypay testnet node!

(You can look up your tx by using a block explorer such as https://live.blockcypher.com/btc-testnet/)


Mainnet Tutorial


[Mobile Wallet]

 

1. Download Eclair Wallet (currently available for Android only)*

* Eclair Wallet installation tutorial (with pictures): https://steemit.com/cryptocurrency/@chronicusprime/how-to-try-out-lightning-network-using-eclair-app-for-android

2. You will need some bitcoin (minimum .01 btc to fund the channel, plus fees for opening and closing the channel. So you should have at least .0011 btc)

Unfortunately there are no active faucets on mainnet that will get you the necessary .0011 btc you need, so either purchase some from a friend or an exchange and send to the address shown in your eclair wallet.

3. Scan the anypay node uris QR code below (or copy/paste the node uris), and fund the channel with at least .001 btc (=100,000 satoshis)

0215d32150103348ac7c1dc7efd4415c90dc3cd0b7bb92d3c43ab3e8b790032f64@18.216.159.148:9735

6. After the transaction has 6 confirmations, you will have successfully opened a lightning channel with the anypay mainnet node!

(You can look up your tx by using a block explorer such as https://live.blockcypher.com/)


[Desktop Terminal Wallet]

 

1. Install lightning network on your computer:*

normal install: https://dev.lightning.community/guides/installation/

docker install: https://dev.lightning.community/guides/docker/

* If you’ve already installed lightning network on testnet, you’ll simply need to change your configuration to run on mainnet and then wait for the blockchain to sync (currently requires ~170gb disc space and several weeks to sync, depending on your download speed)**

** Difficulties with node hanging while syncing (mostly due to connecting with out of sync notes) can be alleviated by using the following homemade program: https://gist.github.com/jleskovar/dfc545148398d81715da02f61bf39b91

2. You will need some bitcoin (minimum .01 btc to fund the channel, plus fees for opening and closing the channel. So you should have at least .0011 btc)

Unfortunately there are no active faucets on mainnet that will get you the necessary .0011 btc you need, so if you don’t have any you’ll need to purchase some from a friend or an exchange, then send to your lightning receiving address (see step 3).

3. Generate a new receiving address through lnd by issuing the following command:

lncli newaddress np2wkh

Send at least .0011 btc to the address that was generated (only the text between the second set of quotes consisting of 34 characters, for example: 36AQnTP3ZtgbkGGonpmwBhCt93tSmSC8Gx).

4. Connect to the anypay node by issuing terminal command:

lncli connect 0215d32150103348ac7c1dc7efd4415c90dc3cd0b7bb92d3c43ab3e8b790032f64@18.216.159.148:9735

5. Open a channel with anypay:

lncli openchannel –node_key=0215d32150103348ac7c1dc7efd4415c90dc3cd0b7bb92d3c43ab3e8b790032f64 –local_amt=100000 –conf_target=1

Note: The –conf_target=1 flag is optional, but was included to allow the client to automatically calculate fees to help get the tx into the next block.*

* This may lead to greater expense than you’d like as tx fees increase, so feel free to remove this flag or use a different flag for your preferred fee calculation method.**

**(Full list of command options can be found here: https://api.lightning.community/#openchannel)

6. After the transaction has 6 confirmations, you will have successfully opened a lightning channel with the anypay mainnet node!

(You can look up your tx by using a block explorer such as https://live.blockcypher.com/)


Now that you’ve opened a channel with the anypay node, whether on testnet or mainnet, you should be able to send/receive lightning payments through your channel. Sending payments will be covered in the next tutorial for both mobile and desktop wallet. We will also cover requesting/receiving payments, however that will only be for the desktop client as currently Eclair Wallet only supports sending payments. This is due to its remote node configuration and requirement to always be online. Support for receiving payments should be added in a future update of Eclair Wallet, though no official statement or release date has been made.

Thanks for reading!

Grant

This entry has 0 replies

Comments open

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>