Skip to content

Instantly share code, notes, and snippets.

@mattcruzz
Last active April 10, 2024 21:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattcruzz/49bea8901d407e382229b73a54e1b53b to your computer and use it in GitHub Desktop.
Save mattcruzz/49bea8901d407e382229b73a54e1b53b to your computer and use it in GitHub Desktop.

btcd + LND Full Node on OSX (w/external SSD)

I've been wanting to run a full node and play with lightning for quite some time now, but my lack of storage on my computer was holding me back. Because that was a pretty weak excuse I went out and bought an external drive and set out to figure out how I make this work. This write up should serve as step by step guide on how to setup a full btcd/LND node with an external SSD to store the bitcoin blockchain.

Pre-requisites

  • An external harddrive
    • Based off of bitcoind, the minimum read/write speed of 100 MB/s, so I will be using a SSD.
    • Must have more than 250GB of storage (the blockchain is currently approaching 250GB, so I will be using 500GB)
  • OSX, this guide is meant for Mac users
  • A broadband Internet connection with upload speeds of at least 400 kilobits (50 kilobytes) per second
  • An unmetered connection, a connection with high upload limits, or a connection you regularly monitor to ensure it doesn’t exceed its upload limits. It’s common for full nodes on high-speed connections to use 200 gigabytes upload or more a month. Download usage is around 20 gigabytes a month, plus around an additional 195 gigabytes the first time you start your node.
  • These are based on Full Node Minimum Requirements

Dependencies

Go ahead and open up your terminal and start

Install Homebrew

Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple's macOS operating system and Linux.

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To install, enter your computer's password when prompted and hit return.

Install Golang

Go is the programming language that LND is written in.

$ brew install go

Now set your $GOPATH environment variable, which 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.

$ echo 'export GOPATH=~/gocode' >> ~/.bash_profile
$ echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bash_profile
$ source ~/.bash_profile

btcd

btcd is an alternative full node bitcoin implementation written in Go (golang). It properly downloads, validates, and serves the block chain using the exact rules (including consensus bugs) for block acceptance as Bitcoin Core. One key difference between btcd and Bitcoin Core is that btcd does NOT include wallet functionality and this was a very intentional design decision.

Install btcd

Run the following commands to obtain btcd, all dependencies, and install it:

$ git clone https://github.com/btcsuite/btcd $GOPATH/src/github.com/btcsuite/btcd
$ cd $GOPATH/src/github.com/btcsuite/btcd
$ GO111MODULE=on go install -v . ./cmd/...

Now, btcd (and utilities) will now be installed in $GOPATH/bin.

Configure btcd.conf

We're going to modify btcd.conf to point the data directory at our external drive, add our rpc credentials, and enable txindex. At this point, if you haven't already, go ahead and plug in your external drive.
By default the configuration file on OSX is located here /Users/${USER}/Library/Application Support/Btcd. Navigate to that directory and open up btcd.conf with your favorite text editor. The btcd.conf file comes with lovely comments that describe the many different options, so feel free to explore and modify this configuration to your liking. However, I'm only going to focus on a few of these options.
To enable an option, you'll have to uncomment it by deleting the semi-colon and then specify your option after the equal sign.

  • datadir=<Path to External Drive>
    • I've named my drive BLOCKCHAIN, so my configuration looks like this datadir=/Volumes/BLOCKCHAIN
  • rpcuser=<RPC username of your choice>
  • rpcpass=<RPC password of your choice>
    • These credentials will allow you to control the built-in RPC server which is used to control and query information from a running btcd process
  • txindex=1
    • According to the official LND repository, this isn't necessary, but it will generally make LND run faster so I opted to include it. Save your changes to the file.

Start btcd

It's now time to start up your node and begin syncing the bitcoin blockchain. The blockchain is currently approaching 250GB, so this process will take upwards of three days. Remember this is an important process in because you're personally verifying every transaction ever recorded on the blockchain. When it is done syncing you can be confident in the integrity of your full node. Now go ahead and enter the following command in the Terminal to begin:

$ btcd

This will start btcd, it will read your newly modified btcd.conf file, and begin syncing the blockchain to your external drive.

Stop btcd

control + C

LND

Installing LND

While btcd is syncing up, go ahead and open a new tab in your terminal CMD+T. Then run the following commands:

go get -d github.com/lightningnetwork/lnd
cd $GOPATH/src/github.com/lightningnetwork/lnd
make && make install

To check that lnd was installed properly run the following command:

make check

Configure LND

DISCLAIMER: I am outlining how to run on the main network. If you're doing any development or just want to play around, it may be a good idea to use the testnet or simnet options. Go ahead and open another tab in your terminal application CMD+T and navigate to this directory /Users/${USER}/Library/Application Support/Lnd. Create a new configuration file and open it up with your favorite text editor. Copy the contents from this file: https://github.com/lightningnetwork/lnd/blob/master/sample-lnd.conf and paste it into your new configuration file. Now we'll need to make a few changes to the [Bitcoin] section. Go ahead and comment out the line containing bitcoin.simnet=1 and add the following lines right below:

; Use Bitcoin's main network
bitcoin.mainnet=1

By default the backend node should be bitcoin.node=btcd, but if that's not the case make sure to also make that change in the configuration file.

Start LND

To start LND, in your second terminal window run the following command:

$ lnd

If you get the following response, then you've successfully started up LND:

Waiting for wallet encryption password. Use lncli create to create a wallet, lncli unlock to unlock an existing wallet, or lncli changepassword to change the password of an existing wallet and unlock it. Then congratulations! You've successfully set up lnd.

Create a Wallet

Now that you're all set up, the first thing you'll want to do is create a wallet. Go ahead and open up a new terminal window and enter the following command:

$ lncli create

Go ahead and create a strong password. Enter n to generate a LND Cipher Seed and hit enter if you don't wish to encrypt it. Make sure to write down your seed offline, so you're able to restore your wallet if you need to.

Fund your Wallet

Before we start this process you'll want to check and make sure LND is fully synced up. Enter the following command:

$ lncli getinfo

If synced_to_chain and synced_to_graph are both true, then we're clear to proceed. If not, go ahead and wait until eveything is synced. \ Now that we're sure everything is synced, we'll generate a bech32 bitcoin address:

$ lncli newaddress p2wkh

LND should respond with something like this:

{ "address": "bc1qtcsnmh7wamdauvpyxrtwx4f3xcsspch3vmypd7" } Go ahead and fund your node by sending BTC to this address. Disclaimer: this is still an early technology, so I would recommend only sending an amount you're willing to lose. This is a layer 1/on-chain transaction so it'll generally take 10-30 minutes to be confirmed. To check the status of the transaction you can use the following command:

$ lncli walletbalance

Alternatively, if you could use the linux watch command to monitor the status. You'll have to brew install watch and then use the following command:

$ watch -t lncli walletbalance

Connect and Open a Channel

First you'll need to find a node to connect with, the resource I used to find a channel was robtex at: https://www.robtex.com/lightning/node. To connect, you'll first need to get that node's info:

$ lncli getnodeinfo <pub key>

For example, I'll be trying to open a channel to the first node, rompert.com🔵

$ lncli getnodeinfo 02ad6fb8d693dc1e4569bcedefadf5f72a931ae027dc0f0c544b34c1c6f3b9a02b

Now with that information you'll try and connect with them.

$ lncli connect <pub key>@<addr>

Connecting with:

$ lncli connect 02ad6fb8d693dc1e4569bcedefadf5f72a931ae027dc0f0c544b34c1c6f3b9a02b@34.239.230.56:9735

To see if this was successful, you'll need to list your peers and verify that one of them is the node you attempted to connect with (has the same public key and ip address):

$ lncli listpeers

If they're listed as one of your peers, now you can attempt to open a channel and fund it:

$ lncli openchannel <pub key> <# of satoshis>

I funded my wallet with ~$20, so making a connection would look like this:

$ lncli openchannel 03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f 210000

If this is successful, you'll receive a txid for your funding transaction. While this transaction is waiting to be confirmed, you should be able to see the pending channel with this command:

$ lncli pendingchannels

When the transaction is confirmed, you'll be able to see the channel with:

$ lncli listchannels

Congratulations, you made it to the end. You can use (LND gRPC API Reference)[https://api.lightning.community/], to begin exploring the Lightning Network!

References

LND Installation Guide
btcd Readme
You can always reach out to the fine people on the LND slack with any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment