How to Setup Bitcoin Core and Lightning Network Node Developer Environment
Tags: bitcoin, lightning, lnd, regtest
Published: 2022-04-11 08:20:02

---
title: How to Setup Bitcoin Core and Lightning Network Node Developer Environment
published: true
description: How to setup bitcoind and lnd
tags: #bitcoin #lightning #lnd #regtest
//cover_image: https://direct_url_to_image.jpg
cover_image: https://res.cloudinary.com/tvpeter/image/upload/v1649414921/start_test_ouxsqk.png
---

Like any other developer environment, for one to build on Bitcoin Core and Lightning Network, you need to setup their (development) environments. 

Note: This writeup is based on implementation on macOS. If you need help setting up for another platform, please reach out and I will be happy to assist.

### Prerequisites:

Please check that you have the following softwares installed on your computer:
- Git 
- python
- Home Brew
- Sqlite

We are going to start with Bitcoin.  To build on Bitcoin, we are going to setup its client software called Bitcoin Core. Bitcoin Core consists of a  `full-node` software for fully validating the blockchain as well as a bitcoin wallet.  We will clone their Github repository and compile.

### Required Dependencies

We will be following instructions found in the ‘doc’ directory of the [repository](https://github.com/bitcoin/bitcoin/tree/master/doc) to install all the required dependencies. Install the following dependencies:

* install Xcode: `xcode-select -—install`
* using home-brew, install automate, lib tool, boost, png-config, and libevent by running:
 `brew install automake libtool boost pkg-config libevent`
- Ensuring that python is installed, you can install the deploy dependencies by running: `pip3 install ds_store mac_alias`.


### Optional Dependencies 
- install berkeley-db@4 if you want to support legacy wallets 
 `brew install berkeley-db@4`
- install qt@5 if you intend to compile GUI: `brew install qt@5`
- To build in QR support for the GUI, install qrencode: `brew install qrencode` 
- to support UPnP port mapping, install miniupnpc: `brew install miniupnpc` 
- to support NAT-PMP port mapping, install libnatpmp: `brew install libnatpmp` 
- to support for ZMQ notifications, install ZMQ: `brew install zeromq`

## Building Bitcoin Core 

Navigate to where you want to compile bitcoin core and clone the repo:

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

**Configure Bitcoin Core:**
We will be configuring our Bitcoin Core to support Wallet (BDB + SQlite) without a GUI. `cd` into bitcoin, and run the following commands:
```
./autogen.sh
./configure --with-gui=no
 ```
Please note that, if you did not install  `berkeley-db@4` stated above, kindly install before running the above command to avoid errors.

**Compile Bitcoin Core:**
Inside the same directory, run the following commands:
```
- make
- make check (to run tests)
```
## Setting up Bitcoin Core to use Regtest

If you are setting up Bitcoin core primarily for development, there is no need to connect to `mainnet` and download the entire block. Therefore, we will be configuring ours to use `regtest`.

Run the below commands to create Bitcoin directory,  its configuration file `bitcoin.conf` and grant appropriate permissions.

```
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"

```
open the Bitcoin configuration file in your editor and add the following:
```
# Daemon Options
server=1
daemon=1
fallbackfee=0.00072
txconfirmtarget=6
# Network Options
regtest=1
#signet=1
#testnet=1
[regtest]
# RPC Options
rpcport=18443
rpcuser=bitcoin
rpcpassword=bitcoin
# ZMQ Options
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
zmqpubhashtx=tcp://127.0.0.1:28332
zmqpubhashblock=tcp://127.0.0.1:28332
```

save and close the above configuration. With the above in place, you can now run your bitcoin core with:

`bitcoind `

Next, we will be setting up our lightning network

Similar to Bitcoin, we are going to setup Lightning network node using Lightning Network Daemon (lnd). LND has several pluggable back-end chain services including btcd (a full-node), bitcoind, and neutrino (a new experimental light client). 

### Requirements:
install Go using home-brew `brew install go`

Navigate to any directory where you want to setup LND and clone the repo:
```
git clone https://github.com/lightningnetwork/lnd

cd lnd

make install
```
To check that lnd was installed properly run the following command:
```
  make check
```
Similar to our bitcoin core installation, we want to configure `lnd` to use `regtest` and connect to our Bitcoin core, so we'll create it's config file in the following directory with the below configuration: 
```
mkdir -p "/Users/${USER}/Library/Application Support/Lnd"

touch "/Users/${USER}/Library/Application Support/Lnd/lnd.conf"

chmod 600 "/Users/${USER}/Library/Application Support/Lnd/lnd.conf"

```
paste the following configuration details in the configuration file:
```
[Application Options]
debuglevel=trace
maxpendingchannels=10

[Bitcoin]
bitcoin.active=1
bitcoin.node=bitcoind
bitcoin.regtest=1     
```

**Creating a wallet**
In one of the terminal tab, run the command 
 ```
lnd
```
and in another tab, create a new wallet with:
```
lncli create
```
This will prompt for a wallet password, and optionally a cipher seed passphrase.
`lnd` will then print a 24 word cipher seed mnemonic, which can be used to recover the wallet in case of data loss. The user should write this down and keep in a safe place.

If you encounter errors at any point during your setup or have any comments, kindly share in the comments section and I will be happy to reply. Thank you for reading.