Bitcoin [tut] getting started with the lightning network!

Status
Not open for further replies.

Strawberrry

Forum Veteran
Hi everyone,

Just a quick tutorial on running your first lightning node and opening a payment channel. Its just as fun as it sounds :)

Warning before we get started: this is a tutorial on using the nitty gritty command line stuff with lightning. You might enjoy using the nice GUI called Zap which is found here, instead: You do not have permission to view the full content of this post. Log in or register now.
Follow the installation instructions there to get started, I won't cover that.

We're going to be using LND which stands for the Lightning Network Daemon, an open source implementation of a lightning node + wallet by Lightning Labs, which I personally have just begun working on. Not sure if its the easiest for beginners, but its the one I'm more familiar with, so I'll start here and maybe add the others later.

The github repository for LND is here: You do not have permission to view the full content of this post. Log in or register now.

Preperation

First, you're going to have to install Go (aka golang). LND requires at least Go version 1.8. And you'll probably want git installed so you can pull updates from github as they happen.

On linux, run the command:
Code:
sudo apt-get install golang-1.8-go

This'll put the binaries in /usr/lib/go-1.8/bin. Then we need to add that to our PATH,
Code:
export PATH=$PATH:/usr/lib/go-1.8/bin

On Mac OS X
Code:
brew install go

Windows probably just has an exe download from the go website, not sure.

Now that go is installed, just a couple more changes to your PATH. The $GOPATH environment variable represents the path to your workspace, by default, $GOPATH is set to ~/go. You will also need to add $GOPATH/bin to your PATH. This ensures that your shell will be able to detect the binaries you install (e.g. lnd and lncli when we're done):
Code:
export GOPATH=~/gocode
export PATH=$PATH:$GOPATH/bin

Once you have go installed, you'll need to install Glide, which is how lnd is built. Simply run this command to install glide:
Code:
go get -u github.com/Masterminds/glide

Building LND

Now you have go and glide set up, we can download the lnd source code from the github repository:
Code:
git clone https://github.com/lightningnetwork/lnd $GOPATH/src/github.com/lightningnetwork/lnd

Now change into the directory with the code you just downloaded:
Code:
cd $GOPATH/src/github.com/lightningnetwork/lnd

And build+install it:
Code:
glide install
go install . ./cmd/..

This will install both lnd (the daemon itself) and lncli (the program you will use to interact with it).

To check it all works, run this command to test it:
Code:
go install; go test -v -p 1 $(go list ./... | grep -v  '/vendor/')

Running LND with neutrino

One way to run LND is by also running your own bitcoin full node with transaction index enabled, but that takes a while to sync and takes up quite a bit of space (~15GB on testnet and ~150GB on mainnet or thereabouts). So I'll cover using the lightclient mode called neutrino first.

neutrino is a new mode which improves a lot of the issues that the old SPV light client mode has, including better privacy, more resistance to DoS, etc.

Because neutrino is relatively new, not many nodes support it, and we need to find one that does. Lucky for us, lightning labs have a public one running for testnet here: faucet.lightning.community which we'll connect to.

To run lnd, use this command:
Code:
lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.node=neutrino --neutrino.connect=faucet.lightning.community

I'll briefly explain the arguments: bitcoin.active tells lnd we are using bitcoin (it also supports litecoin), bitcoin.testnet tells it we are using testnet (LIGHTNING IS NOT READY FOR MAINNET YET. ITS RISKY). We've enabled debug logging in case something goes wrong so you can help us fix it. neutrino is the light client mode, and the connect argument tells it to use the testnet lightning faucet as the full node.

You are now running lnd! You should see it waiting for the wallet to be created/unlocked, so that's our next step :D

Creating a wallet for lnd

To interact with LND now it is running, we need to open a second terminal window, and use the lncli program to communicate with it. LND is waiting for us to create or unlock the wallet, so since this is our first time running, lets make a new wallet:
Code:
lncli create

it'll ask you twice for a password, requiring at least 8 characters iirc, and then once its done you'll see LND start processing headers and everything.

If you are running LND the second time after already creating your wallet, use the
Code:
lncli unlock
command instead

Wait for LND to sync

Syncing the first time might take a while, you can use the following command to get info about its status and see if its synced:
Code:
lncli getinfo

You'll see what testnet block height its up to, and there will be a boolean synced_to_chain flag to say if its synced or not.

Also, make a note of identity_pubkey, because we'll need that later, that's the unique identifier for your node.

Once synced... LETS MAKE A CHANNEL

Now its time to open a channel with the faucet :D

Visit the faucet website, You do not have permission to view the full content of this post. Log in or register now., and copy paste the address of the faucet at the top of the page. At the moment it looks like this but it might change:
Code:
02c39955c1579afe4824dc0ef4493fdf7f3660b158cf6d367d8570b9f19683afb5@159.203.125.125
Connect to the node using this command:
Code:
lncli connect 02c39955c1579afe4824dc0ef4493fdf7f3660b158cf6d367d8570b9f19683afb5@159.203.125.125
Make sure we're connected by running this command:
Code:
lncli listpeers

You should see it there. Now go back to the website, and fill out the form to make a new channel. Copy and paste identity_pubkey from your getinfo command earlier into the Target Node box, fill in the other boxes with a bit of money (be considerate of others using the faucet, choose something like 500000 satoshis for the channel and push maybe half of that to your side, 250000 satoshis). Then hit submit on the form.

Remember, these numbers are all testnet bitcoins not real bitcoins, they have no value so there's no point taking more than you need.

Now head back to your lightning node, and run this command:
Code:
lncli pendingchannels

You should see the channel there. It'll remain pending until the funding transaction confirms (leave your PC on until it does). Once its confirmed you'll see it when you run this command:
Code:
lncli listchannels

And now you've opened your first channel!

I'll leave it there for today, you can use the -help flag to get more info about other commands with lncli, for example to send a payment to the faucet node you have your channel open with, or even multihop payments to others in the network. Here's a good tutorial: You do not have permission to view the full content of this post. Log in or register now.

Enjoy!

Resources
Testnet lighting network explorer: You do not have permission to view the full content of this post. Log in or register now.
Mainnet explorer: You do not have permission to view the full content of this post. Log in or register now.
Mainnet network info: You do not have permission to view the full content of this post. Log in or register now.
Lightning network website: You do not have permission to view the full content of this post. Log in or register now. (with links to papers, etc.)
LN megathread on reddit: You do not have permission to view the full content of this post. Log in or register now.
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 584
    Views
  • 2
    Participants
Last reply from:
PHC-Phats

Online now

Members online
520
Guests online
843
Total visitors
1,363

Forum statistics

Threads
2,275,108
Posts
28,960,686
Members
1,233,596
Latest member
Cox beh
Back
Top