The Easiest Bitcoin Lighting Node Tutorial

in #lightningnetwork5 years ago (edited)

Setting up Lightning network on Vultr



The following guide is used to set up BTC Lightning on Vultr. You will need to have some knowledge of Linux but mostly copy and paste will work just fine.

Head over to Vultr and grab yourself an ubuntu 18.04 instance with 320gb of storage, this will cost at the time of writing ~($0.134/hr).


Pick your location
step1.PNG


Pick your operating system. Please choose 64bit Ubuntu 18.04
step2.PNG


Choose a 320gb instance and DDOS protection
step3.PNG


After you have launched your instance you will want to create an ssh key by following this ssh key creation guide and use it to access your server.

step4.png


On your newly created server please type the following commands to update the system, setup the firewall and install docker.

#update the system
$ sudo apt-get update

#upgrade the system
$ sudo apt-get upgrade

#install docker and docker-compose
$ sudo apt-get install docker.io docker-compose



Next we will set up the firewall too allow ports 8333 and 9735

#allow port 8333
$ sudo ufw allow 8333

#allow outgoing 8333
$ sudo ufw allow out 8333

#allow port 9735
$ sudo ufw allow 9735

#allow outgoing 9735
$ sudo ufw allow out 9735

#enable ufw (this my interupt your connection please say yes)
$ sudo ufw enable



If this worked you should see something similar to this

To                         Action      From
--                         ------      ----
9735                       ALLOW       Anywhere
8333                       ALLOW       Anywhere
9735 (v6)                  ALLOW       Anywhere (v6)
8333 (v6)                  ALLOW       Anywhere (v6)
9735                       ALLOW OUT   Anywhere
8333                       ALLOW OUT   Anywhere
9735 (v6)                  ALLOW OUT   Anywhere (v6)
8333 (v6)                  ALLOW OUT   Anywhere (v6)
...


We have to create a couple of directories for our docker images please type the following commands on your server

$ mkdir -p /scratch/bitcoin/mainnet/bitcoind

$ mkdir -p /scratch/bitcoin/mainnet/clightning



Next we need to create the bitcoind and clightning containers in docker.

#1. Create an empty docker-compose file in nano.
$ cd ~

$ nano docker-compose.yml

#2. Copy and paste the docker-compose.yml code below

#3. Save the edited file (Ctrl-X, Y, <Enter>)



Paste this code into step #2 above and change the <Lightning node name> and <droplet IP-address> to match your nodes name and IP address.

version: "3"
services:
  bitcoind:
    image: nicolasdorier/docker-bitcoin:0.16.0
    container_name: bitcoind
    environment:
      BITCOIN_EXTRA_ARGS: |
        testnet=0
        whitelist=0.0.0.0/0
        server=1
        rpcuser=rpcuser
        rpcpassword=rpcpass
    expose:
      - "8333"
    ports:
      - "0.0.0.0:8333:8333"
    volumes:
      - "/scratch/bitcoin/mainnet/bitcoind:/data"
  clightning_bitcoin:
    image: elementsproject/lightningd
    container_name: lightning
    command:
      - --bitcoin-rpcconnect=bitcoind
      - --bitcoin-rpcuser=rpcuser
      - --bitcoin-rpcpassword=rpcpass
      - --network=bitcoin
      - --alias=<Lightning node name>
      - --rgb=FF4500
      - --log-level=debug
      - --announce-addr=<droplet IP-address>:9735
    environment:
      EXPOSE_TCP: "true"
    expose:
      - "9735"
    ports:
      - "0.0.0.0:9735:9735"
    volumes:
      - "/scratch/bitcoin/mainnet/clightning:/root/.lightning"
      - "/scratch/bitcoin/mainnet/bitcoind:/etc/bitcoin"
    links:
      - bitcoind



#install screen
$ sudo apt-get install screen

#create a new screen named node
#to exit this screen press ctrl+a+d

$ screen -S node


Next lets fire up your newly created node!

$ docker-compose up


After a very long time



#exit out of node screen by pressing ctrl+a+d

Now we will write a couple of cli scripts to command our node and wallet.

First, our bitcoin-cli

# 1. Create script and edit script (see below).
$ nano /bin/bitcoin-cli

# 2. Copy and paste script below

# 3. Save the edited file (Ctrl-X, Y, <Enter>)

# 4. Make script executable.
$ chmod +x /bin/bitcoin-cli

# 5. Confirm script is working. This command shows the wallet info.
$ bitcoin-cli getwalletinfo



Copy and paste following script in to step #2 above

#!/usr/bin/env bash
docker exec bitcoind bitcoin-cli -rpcuser=rpcuser -rpcpassword=rpcpass "$@"



Second, our lightning-cli

# 1. Create and edit script (See below).
$ nano /bin/lightning-cli

# 2. Copy and paste the script below

# 3. Save the edited file (Ctrl-X, Y, <Enter>)

# 4. Make script executable.
$ chmod +x /bin/lightning-cli

# 5. Confirm script is working. 
$ lightning-cli getinfo



Copy this to step 2 above.

#!/usr/bin/env bash
docker exec lightning lightning-cli "$@"

That's it! Now you have a functional lightning node



Funding your node and opening Channels

It's pretty neat that we have this setup but lets make it better! We will connect to a payment channel, fund our bitcoin wallet and then fund our lightning node.

Connecting to a channel is real simple all you need is the Node ID, IP address and port number. Let's connect to my node!

$ lightning-cli connect 02ffad7dfb8ce69cb7d6a7f1f02aa7944121c43b9ec6ea2ed2ed5b10ce34b0cd90@45.76.246.246:9735



Funding your bitcoin wallet

$ bitcoin-cli getnewaddress

This will give you the bitcoin address you will fund. This is still experimental so please send only what you are willing to lose


After sometime please check our wallet by entering the following command

$ bitcoin-cli getwalletinfo



Next we will fund our lightning node

#create new lightning address to be funded
$ lightning-cli newaddr



Now send BTC to lightning node

bitcoin-cli sendtoaddress <address> <amount_in_bitcoins>


Funding the new channel

To fund the newly created channel just enter the following command replacing my channels information with the channel you would like to fund.

#1. If needed, list connections. Unfunded channels will have 
#state set to 'GOSSIPING'
$ lightning-cli listpeers

#2. Fund the channel to our peer Canna-Curate-StJohns
#with 400 kSat.

$ lightning-cli fundchannel 02ffad7dfb8ce69cb7d6a7f1f02aa7944121c43b9ec6ea2ed2ed5b10ce34b0cd90 400000


If you enjoyed this post please click here

divider.png

Please join the Canna-Curate Server with HashKings and be part of this exciting new adventure! 2019 has arrived along with

Canna-Curate | The #1 Cannabis Curation Trail on Steemit

@jonyoudyer (@canna-curate)
@bluntsmasha aka CryptnoToad
@fracasgrimm (@greenhouseradio)
@qwoyn (@hashkings)



This tutorial is based on the work of:

Ronald Mannak
-The lightning network how to install and hopefully make money
-Installing Lightning Network part 2: Here We Go Again


Jason van den Berg
-Setting up and transacting on the bitcoin lightning network


Please consider donating BTC to my lightning node!

btcCoinbase.PNG

3CeZBXVdNkwrdjjdvVpLS677fNZwpVBgs9

Sort:  

Curated for #informationwar (by @Gregorypatrick)

Ways you can help the @informationwar!

  • Upvote this comment or Delegate Steem Power. 25 SP 50 SP 100 SP or Join the curation trail here.
  • Tutorials on all ways to support us and useful resources here

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64534.17
ETH 3150.15
USDT 1.00
SBD 4.01