Setting Up a Bitcoin and Lightning Network Daemon on Mac from source

timothy_masiko

Timothy Masiko

Posted on January 31, 2023

Setting Up a Bitcoin and Lightning Network Daemon on Mac from source

Hey If you are here you might be already interested in getting yourself set up on this cool Lightning network mission , I found quite a couple of challenges in getting an easy guide to help me get setup much faster so i decided to write this article. Enjoy!

This guide describes how to build bitcoind (without GUI) and lnd on mac

This is also heavily based on Michael Goldstein article and Bitcoin MacOS Build Guide

Step one

Update your build tools with the following command from your terminal:

xcode-select --install
Enter fullscreen mode Exit fullscreen mode

You can skip it incase you are certain your build tools are up to date

We shall be using brew so ensure you have brew installed on your laptop

To install the Homebrew package manager, see: link

Install Dependencies

Run the following from your terminal:

brew install automake libtool boost pkg-config libevent

Enter fullscreen mode Exit fullscreen mode

Clone Bitcoin repository

On the assumption that you have git installed clone the repo

git clone https://github.com/bitcoin/bitcoin.git

Enter fullscreen mode Exit fullscreen mode

Install additional Dependencies

We shall be using ZMQ

brew install zeromq
Enter fullscreen mode Exit fullscreen mode

ZMQ is automatically compiled in and enabled if the dependency is detected.

For more information on ZMQ,see

Configuring Bitcoin Core

lets now setup the core , from your terminal cd to bitcoin cloned directory

run these two commands

./autogen.sh
./configure --without-wallet --with-gui=no
Enter fullscreen mode Exit fullscreen mode

Compile

After configuration, you are ready to compile. Run the following in your terminal to compile Bitcoin Core:

make        # use "-j N" here for N parallel jobs i.e make -j "$(($(sysctl -n hw.physicalcpu)+1))" this gets to speed up the process by usage of the cpu 
make check  # Run tests if Python 3 is available
Enter fullscreen mode Exit fullscreen mode

Running Bitcoin Core

Before running, you need to create an empty configuration file:

mkdir -p "/Users/${USER}/Library/Application Support/Bitcoin"

touch "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf"

chmod 600 "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf"
Enter fullscreen mode Exit fullscreen mode

Bitcoin Core should be available at ./src/bitcoind

You should be able to also access certain other commands like

./src/bitcoind -daemon      # Starts the bitcoin daemon.
./src/bitcoin-cli --help    # Outputs a list of command-line options.
./src/bitcoin-cli help      # Outputs a list of RPC commands when the daemon is running.
./src/qt/bitcoin-qt -server # Starts the bitcoin-qt server mode, allows bitcoin-cli control
Enter fullscreen mode Exit fullscreen mode

Setting up Bitcoin

Next, you’ll want to create a configuration file bitcoin.conf that goes our created Bitcoin directory in Library:

regtest=1
daemon=1
txindex=1
rpcauth=<rpc auth username and password>
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
Enter fullscreen mode Exit fullscreen mode

This tells Bitcoin Core to use regtest mode, run as a daemon, and keep an index of all transactions. It also sets up RPC authentication and ZMQ ports for LND to use to communicate with the node. To produce the value to enter for rpcauth, use the script found at ./share/rpcauth/rpcauth.py from the cloned git repository

run the command

python rpcauth.py <<username>> // ensure you're are using python3
Enter fullscreen mode Exit fullscreen mode

copy the rpcauth and password logged we shall use it in our bitcoin.conf file

Make adjustments to your bitcoin.conf file you can either use nano or a text editor to add

rpcauth=#####
rpcuser=<<username>> // the username you used with the script
rpcpassword= ## password generated with the script

Enter fullscreen mode Exit fullscreen mode

In your bitcoin repository directory

lets Go ahead and mine a few blocks
run the command

./src/bitcoin-cli -generate 5

Enter fullscreen mode Exit fullscreen mode

Coins are not spendable by miners until there are 100 confirmations, so let’s speed things along with more blocks.

./src/bitcoin-cli -generate 101
Enter fullscreen mode Exit fullscreen mode

Now you should see a positive balance:

./src/bitcoin-cli getbalance
Enter fullscreen mode Exit fullscreen mode

Bitcoin is up and running!

LND Setup

Let’s make a directory for our LND nodes. Yes, nodes. We’re going to make two of them.

mkdir -p "/Users/${USER}/Library/Application Support/Lnd

mkdir -p "/Users/${USER}/Library/Application Support/Lnd2
Enter fullscreen mode Exit fullscreen mode

Now let’s make configuration files. The first node can use default values, so it will be a simpler file. Save it as lnd.conf in the Lnd directory.

[Bitcoin]

bitcoin.active=1
bitcoin.regtest=1
bitcoin.node=bitcoind

[Bitcoind]

bitcoind.rpchost=localhost
bitcoind.rpcuser=<<username>>
bitcoind.rpcpass=<<generated password from the script>>
bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333
Enter fullscreen mode Exit fullscreen mode

This tells LND about the Bitcoin node it is using and the RPC and ZMQ details for communicating. Since this is a local test environment, the password is not very secure. If you used a different password in the Bitcoin RPC auth script, be sure to update the value here.

Now we will make lnd.conf in the Lnd2 directory:

[Application Options]

listen=0.0.0.0:9734
rpclisten=localhost:11009
restlisten=0.0.0.0:8180

[Bitcoin]

bitcoin.active=1
bitcoin.regtest=1
bitcoin.node=bitcoind

[Bitcoind]

bitcoind.rpchost=localhost
bitcoind.rpcuser=<<username>>
bitcoind.rpcpass=<<password>>
bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333


Enter fullscreen mode Exit fullscreen mode

Dont forget to replace the username and password

run this command in your terminal

export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
Enter fullscreen mode Exit fullscreen mode

Now let’s set up some further aliases on our mac by adding the lines below in our ~/.zshrc file

export LND1_DIR="$HOME/Library/Application\ Support/Lnd"
export LND2_DIR="$HOME/Library/Application\ Support/Lnd2"

alias lnd1="lnd --lnddir=$LND1_DIR";
alias lncli1="lncli -n regtest --lnddir=$LND1_DIR"


alias lnd2="lnd --lnddir=$LND2_DIR";
alias lncli2="lncli -n regtest --lnddir=$LND2_DIR --rpcserver=localhost:11009"
Enter fullscreen mode Exit fullscreen mode

Save the adjustments and run

source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

To check our lightning Node run this in the terminal

lnd1
Enter fullscreen mode Exit fullscreen mode

once you're good to go follow up Running LND

Hope this is helpful ✨

Do Like ❤️ & Save 🔖

Do Follow me here on dev.to ✅ for more Bitcoin Lightning content 👨‍💻

💖 💪 🙅 🚩
timothy_masiko
Timothy Masiko

Posted on January 31, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related