Skip to content

Instantly share code, notes, and snippets.

@szollo
Last active February 5, 2018 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szollo/576732cabb427b7d94da14fd3087427f to your computer and use it in GitHub Desktop.
Save szollo/576732cabb427b7d94da14fd3087427f to your computer and use it in GitHub Desktop.
Set up a LN node on mainnet using bitcoind and lightningd

Run a Lightning Network node on mainnet

Disclaimer

Please note that running LN on mainnet is NOT deemed safe for mainnet yet - all testing should be done on testnet. Be aware of the risks and only send bitcoins you are willing to lose.

This quick gist uses bitcoind and lightningd to run a LN node on mainnet, and it assumes the following:

  • Ubuntu Linux (16.04.3 on this walkthrough)
  • some spare bitcoins you are willing to lose

Install all prerequired software

sudo apt-get install -y autoconf automake build-essential git libtool libgmp-dev libsqlite3-dev python python3 net-tools jq

Install bitcoind

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:bitcoin/bitcoin
sudo apt-get update
sudo apt-get install -y bitcoind

Clone and build lightningd

mkdir builds && cd builds
git clone https://github.com/ElementsProject/lightning.git
cd lightning
make

Configure bitcoind

  1. Add the following lines to bitcoin.conf
walletbroadcast=0
txindex=1

Start and sync bitcoind

bitcoind -daemon

Monitor bitcoind sync progress

Seeing as the current blockchain size is ~170GB, this might take a few days to fully download.

  1. Make a file called check_lastblock_date.sh
#!/bin/bash
lastblockdate=`bitcoin-cli getblockchaininfo | jq .mediantime`
blockdate=`date -d @$lastblockdate`
echo -e "The date of the last synchronised block is: \n $blockdate"
  1. Run a watch command to monitor it - time configurable, I chose 5 seconds: watch -n 5 ./check_lastblock_date.sh

(Optional) Add a silly name to your new Lightning node

Paste the following on your Lightning config (by default found in ~/.lightning/config)

alias=INSERTNAMEHERE

Run LN on mainnet (running from the root of the cloned repository)

./lightningd/lightningd --network=bitcoin --log-level=debug

Generate new LN address

This will be the multisig address used as the LN node wallet. Send money to it from any Bitcoin wallet, and wait six confirmations.

./cli/lightning-cli newaddr

Once six confirmations have passed, make sure funds have arrived (they will be denominated in satoshi)

./cli/lightning-cli listfunds

Connect to a LN node and fund channel to it

Pick any node on http://lnd.rompert.com/, and replace node_id, node_ip and port as needed. Well connected nodes are somewhat preferred, as it means fewer hops and lower fees.

./cli/lightning-cli connect <node_id> <node_ip> [<port>]
./cli/lightning-cli fundchannel <node_id> <amount in satoshis>

Check that the funding is confirmed and now public

NODE_ID=`./cli/lightning-cli getinfo | jq -r .id` # saves your node ID on a variable
./cli/lightning-cli listchannels | grep $NODE_ID # you want to see the channel open, and "public" set as "true" - when this is done, the channel has been funded

You're now ready to pay and receive payments!

Below is the payment part, once you are sent the long string (BOLT #11 encoded)

Analyse the BOLT encoded payment - shows metadata such as amount, description, timestamp, expiry date, etc.

./cli/lightning-cli decodepay <payment BOLT string> | jq

Pay

./cli/lightning-cli pay <payment BOLT string>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment