BTC RPC Explorer
Time: 20 minutes
Having your own block explorer helps you in ensuring your privacy, as you no longer have to consult a public block explorer. This way you can check your transactions undisturbed to see if they are still in the mempool or have already been validated.
The Block Explorer we are going to use is BTC RPC Explorer by Dan Janosik.
Note that this section is dependent on the NodeJS installation. You cannot proceed if you do not have NodeJS installed on the Raspberry Pi.
Preparation
There are a number of requirements that you must meet in order to run this block explorer:
- You must have a full node running of which the blockchain is complete.
- Your node must also have an index of all transactions.
- You must have a recent version of NodeJS running.
Full node
You're on the road to node. If you are doing it in the right order you have Bitcoin Core installed by now. If not do that first.
Transaction Index
Login to your Pi and open the bitcoin configuration file.
nano /home/ubuntu/.bitcoin/bitcoin.conf
Check to see if the line txindex=1
appears in it. If not, add it and save your changes with Ctrl + X
followed by Y
.
Next, restart bitcoind
.
sudo systemctl restart bitcoind
Firewall
Again, the firewall needs to be updated. The port over which BTC RPC Explorer shows up is 3002.
sudo ufw allow 3002 comment "Port for BTC-RPC-Explorer"
Installation
Make sure you are in the home directory.
cd ~
Get the source code in.
git clone https://github.com/janoside/btc-rpc-explorer
Enter the BTC RPC Explorer directory.
cd btc-rpc-explorer
Grab the latest release.
git checkout v3.4.0
Install BTC RPC Explorer and then create the configuration file .env
.
npm installnano .env
Paste the following lines in there.
BTCEXP_HOST=IP ADDRESS OF PIBTCEXP_PORT=3002BTCEXP_BITCOIND_HOST=127.0.0.1BTCEXP_BITCOIND_PORT=8332BTCEXP_BITCOIND_COOKIE=/home/ubuntu/.bitcoin/.cookieBTCEXP_BITCOIND_RPC_TIMEOUT=5000BTCEXP_PRIVACY_MODE=true
Modify the text IP ADDRESS OF PI
to what is applicable to you. So replace it with something similar to 192.168.1.6
. Save the file with Ctrl + X
followed by Y
.
Open the file .env-sample
to see what other options there are.
Automation
Now make sure that the BTC-RPC-Explorer starts automatically and runs as a service when your Pi reboots.
sudo nano /etc/systemd/system/btc-rpc-explorer.service
The contents of the file should look like this. In particular, the path to the WorkingDirectory
is important.
[Unit]Description=BTC-RPC-ExplorerRequires=bitcoind.serviceAfter=bitcoind.service[Service]WorkingDirectory=/home/ubuntu/btc-rpc-explorerExecStart=npm run startUser=ubuntuGroup=ubuntuType=simpleRestart=on-failureTimeoutSec=120RestartSec=30[Install]WantedBy=multi-user.target
Save the file with Ctrl + X
followed by Y
.
With the following two commands, activate and start the service.
sudo systemctl enable btc-rpc-explorersudo systemctl start btc-rpc-explorer
Now in Firefox on your PC, open a tab to http://IP-ADRES FROM PI:3002
to see if it works. For example http://192.168.1.6:3002
.
Updating
If there is a new version available for BTC RPC Explorer you can easily update it by getting the new source with Git and installing it. First stop the service and then start it again as shown below.
sudo systemctl stop btc-rpc-explorer
Enter the BTC RPC Explorer directory.
cd ~/btc-rpc-explorer
Update the repository with the latest changes via Git.
git fetch --all
Show the latest version/tag/release.
git describe --tags `git rev-list --tags --max-count=1``
Retrieve the changes from the latest release.
git checkout -f <OUTPUT FROM PREVIOUS STEP> #example: v3.4.0
Install via NPM.
npm install
Restart the service after install is finished.
sudo systemctl start btc-rpc-explorer
Tor
You can also make the service available through Tor. First, we modify the Tor configuration to create a new hidden service.
sudo nano /etc/tor/torrc
In the file that opens, add the following three lines at the bottom.
HiddenServiceDir /var/lib/tor/btc-rpc-explorerHiddenServiceVersion 3HiddenServicePort 3002 127.0.0.1:3002
After Tor is configured we need to create the appropriate directories and assign permissions.
sudo mkdir /var/lib/tor/btc-rpc-explorersudo chown -R debian-tor:debian-tor /var/lib/tor/btc-rpc-explorersudo chmod 700 /var/lib/tor/btc-rpc-explorer
Restart Tor with:
sudo systemctl restart tor
Find the onion address with the following command:
sudo cat /var/lib/tor/btc-rpc-explorer/hostname
Enter this (with port number) into your Tor browser. The BTC RPC Explorer homepage should appear.
Linking with Electrum Server
If you followed the Electrum Server (Electrs, Electrum X, or Electrum Personal Server) guide, you can connect BTC RPC Explorer directly to it for enhanced privacy. Modify the configuration file of BTC RPC Explorer.
nano ~/btc-rpc-explorer/.env
At the bottom, add the following two lines:
BTCEXP_ADDRESS_API=electrumBTCEXP_ELECTRUM_SERVERS=tcp://127.0.0.1:50001
If you want to make sure that the explorer only uses your own backend, you can also modify the service and pass along that it should only run when the Electrum Server is running. The example below shows Electrs as an example, but modify it as appropriate for you.
sudo nano /etc/systemd/system/btc-rpc-explorer.service
The custom service will then look like this:
[Unit]Description=BTC-RPC-ExplorerRequires=electrs.serviceAfter=electrs.service[Service]WorkingDirectory=/home/ubuntu/btc-rpc-explorerExecStart=npm run startUser=ubuntuGroup=ubuntuType=simpleRestart=on-failureTimeoutSec=120RestartSec=30[Install]WantedBy=multi-user.target
This way Electrs waits for Bitcoin Core and BTC RPC Explorer waits for Electrs.
After modifying services, systemctl needs to be reloaded briefly with systemctl daemon-reload
. Your password is needed for this.
Finally, restart the explorer service to make the new configuration effective and use your own backend.
sudo systemctl restart btc-rpc-explorer