Self Sovereign Bitcoin Stack, Part 1 — The Node
By: Adam Gall
Tags: Server, Ubuntu, Full Node, Bitcoin

“Using Bitcoin” can mean different things to different people. It’s a spectrum.

Some would say that simply having any exposure to Bitcoin is “using Bitcoin”. That could be with a Coinbase account, or “holding” GBTC in the Greyscale Bitcoin Trust.

But neither of these options provide the individual with “the point” of Bitcoin.

I don’t want to speak for everyone, but in my view, “the point” of bitcoin is “self sovereign money”. Holding, spending, and receiving money with as little trust as possible placed into other people, governments, and institutions.

This blog series will show you how to set up your own usable Bitcoin Stack, so that you can hold, spend, and receive bitcoin, trusting only in the software that you’re running on your own hardware.

The Stack

Bitcoin Core Full Node <- we are here

ElectrumX Server

Block Explorer

Lightning Network Daemon Node

After the above stack is installed and running on a computer in your network, you will be able to:

use a wallet with your own keys to hold, spend, and receive bitcoin (we’ll use Electrum, which uses ElectrumX and the Full Node)

view and navigate the Bitcoin blockchain on a beautiful, friendly, easy-to-use website (we’ll set up a block explorer on your network, which connects to your own block explorer which grabs data from your ElectrumX server and your Full Node — my own copy is running at https://btc.gall.pro)

use the Lightning Network, by opening, closing, funding, and using your own channels (we’ll use the Zap suite of LN wallet software, which can connect directly to your own Lightning Network Node)

Prerequisites

For this tutorial, you need to have a computer on your network that’s running a Linux system based off of Debian. I’m no Linux expert, and Ubuntu seemed pretty user-friendly, so that’s what I went with on my own server.

If you have an old laptop or desktop computer, this is a great option to put it back to work. I had a tower full of hardware that I built a decade ago that is currently running my bitcoin stack. There’s no monitor hooked up to it, it just sits in the corner, serving all of my bitcoin needs for me.

Get a fresh Ubuntu. I choose Ubuntu Server, and only interact with it via SSH from my laptop. Ubuntu Server has no window system, you only interact with it via Terminal prompts. This guide is going to be 100% text-based, no visual elements.

You can also install Ubuntu Desktop. I suggest you do, if you’re installing this on a laptop, cause it’ll be nice to look at something other than your Terminal when you open it up.

Download Bitcoin Core

Log into your Ubuntu machine, and let’s make a new folder for downloading the Bitcoin Core binary.

~$ mkdir btc-bin

~$ cd btc-bin

Next let’s download the latest linux version of Bitcoin Core. We can see which version that is if we use a browser to navigate to https://bitcoincore.org/en/download/. At the time of writing, this is Bitcoin Core version 0.19.1.

Let’s verify that this downloaded file hasn’t been corrupted. Download the list of cryptographic checksums, and use them to check the file.



~/btc-bin$ sha256sum --ignore-missing --check SHA256SUMS.asc ~/btc-bin$ wget https://bitcoincore.org/bin/bitcoin-core-0.19.1/SHA256SUMS.asc ~/btc-bin$ sha256sum --ignore-missing --check SHA256SUMS.asc

You should see an output with at least one line saying:

bitcoin-0.19.1-x86_64-linux-gnu.tar.gz: OK

As long as you see that, all good. You can safely ignore any warnings.

Finally, let’s make sure these checksums were actually signed by the Bitcoin Core release team (to verify that every bit of this file was signed-off)

~/btc-bin$ gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 01EA5486DE18A882D4C2684590C8019E36C2E964

~/btc-bin$ gpg --verify SHA256SUMS.asc

You should see a line that says:

gpg: Good signature from ...

and another line that says:

Primary key fingerprint: 01EA 5486 DE18 A882 D4C2 6845 90C8 019E 36C2 E964

If you’d like, you can read more about this verification process here: https://bitcoincore.org/en/download/#verify-your-download

Phew! All that, and the only thing we’ve done so far was download a compressed file.

Let’s unpack that tarball

~/btc-bin$ tar -xzf bitcoin-0.19.1-x86_64-linux-gnu.tar.gz

This will result in a new folder in btc-bin called bitcoin-0.19.1 . If you navigate in there, there’s a folder called bin , and inside there is an executable file called bitcoind ! That’s what we’re after. Let’s go in there.

~/btc-bin$ cd bitcoin-0.19.1/bin

In order to be able to execute bitcoind , we need to add it to our PATH . Let’s do that by creating a symlink in /usr/local/bin .

~/btc-bin/bitcoin-0.19.1/bin$ ln -s bitcoind /usr/local/bin/bitcoind

Excellent! Now, anywhere on your system, you have access to run the bitcoind Bitcoin Core Daemon Full Node. Let’s test that by heading back to your home folder and checking the version of bitcoind .

~/btc-bin/bitcoin-0.19.1/bin$ cd ~

~$ bitcoind --version

You should see output that starts with this line:

Bitcoin Core version v0.19.1

Congratulations! 🎉 You now have a copy of the Bitcoin Core program on your machine, ready to sync with the network.

Configure Bitcoin Core

As alluded to at the start of this guide, there are many ways to use Bitcoin. Due to the way that we are setting up our Bitcoin stack here, we need to configure our version of Bitcoin Core a bit, so that the other pieces of software in our stack can interact with it properly.

Here’s how to do that.

We’ll tell Bitcoin Core to look for a configuration file at ~/.bitcoin/bitcoin.conf , so we just need to make that (folder and) file

~$ mkdir .bitcoin

~$ touch .bitcoin/bitcoin.conf

and then fill it with the following content (using your favorite text editor, like vim or nano , or a graphical one if you’re using Ubuntu Desktop)

server=1

txindex=1 rpcuser=<make-up-a-username>

rpcpassword=<some-really-long-random-password-here>

rpcworkqueue=256 disablewallet=1 zmqpubrawblock=tcp://127.0.0.1:28332

zmqpubrawtx=tcp://127.0.0.1:28333

Be sure to change the values of rpcuser and rpcpassword .

On your router, open up port 8333 and forward it to your computer where Bitcoin Core will be running.

Set up the service

We want this stack to be as foolproof as possible.

If your computer restarts, you shouldn’t have to do anything. Bitcoin Core needs to start up on it’s own and get re-synced with the network.

Thankfully we can use systemd for that. We can basically tell Ubuntu, that whenever the system turns on, it needs to run a script, and we can have that script simply be “start the bitcoind executable”.

Make a file with the following content:

[Unit]

Description=Bitcoin daemon

After=network.target [Service]

User=<user>

Group=<user> Type=forking

PIDFile=/home/<user>/.bitcoin/bitcoind.pid

ExecStart=/usr/local/bin/bitcoind -daemon \

-conf=/home/<user>/.bitcoin/bitcoin.conf \

-pid=/home/<user>/.bitcoin/bitcoind.pid Restart=on-failure [Install]

WantedBy=multi-user.target

And save it at /etc/systemd/system/ with a filename of bitcoind.service

You’ll need to provide sudo access to save this file into the /etc/systemd/system/ directory.

Be sure to update that file with your actual Ubuntu username wherever you see <user> .

The last thing you need to do is create a file called bitcoind.pid in ~/.bitcoin/ , right next to your bitcoin.conf file.

Once this file is created at /etc/systemd/system/bitcoind.service , we need to reload the systemd daemon, then enable the service (so that it starts automatically after the system is rebooted), then start the service (so that it starts right now).

~$ sudo systemctl daemon-reload

~$ sudo systemctl enable bitcoind.service

~$ sudo systemctl start bitcoind.service

Bitcoin Core is now running on your computer!

In a new terminal window, we can follow the logs to make sure it’s syncing properly.

~$ tail -f .bitcoin/debug.log

Hopefully you see all kinds of logs indicating that Bitcoin Core is starting up, connecting to peers, and syncing the blockchain.

Now we play the waiting game. In a day or two or three you’ll see the progress indicator value in the logs creep closer and closer to 1.000000 , and when that happens, you’re fully synced!

Fin

That’s all for now.

If you’ve followed this guide all the way here, you’ve got Bitcoin Core installed and syncing on a computer that you control. This lays the groundwork for all kinds of other fun services and softwares that we’ll install next, which GREATLY increase the actual usability of your full node.

This is my blockchain. There are many like it, but this one is mine.

I’ll include a link to Part 2: ElectrumX Server here, when that’s ready.

Follow me on Twitter: https://twitter.com/trainface