Blockchain explorer

Blockchain explorer

Run your own private blockchain explorer with BTC RPC Explorer (opens in a new tab). Trust your node, not some external services.

BTC RPC Explorer home screen with dark theme

Run your own blockchain explorer

After the MicroBolt runs your own fully validated node, and even acts as a backend for your hardware signing device with Electrum server, an important puzzle piece to improve privacy and financial sovereignty is your own Blockchain Explorer. It lets you query transactions, addresses, and blocks of your choice. You no longer need to leak information by querying a third-party blockchain explorer that can be used to get your location and cluster addresses.

Preparations

Transaction indexing

For the BTC RPC Explorer to work, you need your full node to index all transactions.

  • If you followed this guide, the transaction index parameter is already enabled (txindex=1), and you can skip to the next section.
  • If this is not the case, you need to set the txindex=1 parameter in your Bitcoin client configuration file (bitcoin.conf): Bitcoin node configuration.
  • After adding the parameter, restart Bitcoin client, which will now index the whole blockchain
$SU rc-service bitcoind restart

Please note that reindexing can take more than a day. You can follow the progress using

tail -f /var/log/bitcoind/debug.log

Install dependencies

  • Install Node.js using the apk package manager.

These are make dependencies (safe to remove after installation, if you want)

$SU apk add npm

These are runtime dependencies

$SU apk add nodejs-current

Create the btc-rpc-explorer user/group

$SU addgroup -S btc-rpc-explorer
$SU adduser \
    -S \
    -D \
    -H \
    -h /dev/null \
    -s /sbin/nologin \
    -G btc-rpc-explorer \
    -g btc-rpc-explorer \
    btc-rpc-explorer

Add btc-rpc-explorer user to the bitcoin group

$SU adduser btc-rpc-explorer bitcoin

Add satoshi user to the btc-rpc-explorer group

$SU adduser satoshi btc-rpc-explorer

Firewall & reverse proxy

In the Security section, we set up NGINX as a reverse proxy. Now we can add the BTC RPC Explorer configuration.

  • Enable NGINX reverse proxy to route external encrypted HTTPS traffic internally to the BTC RPC Explorer
$SU $EDITOR /etc/nginx/streams-available/btc-rpc-explorer-reverse-proxy.conf
/etc/nginx/streams-available/btc-rpc-explorer-reverse-proxy.conf
upstream btc-rpc-explorer {
    server 127.0.0.1:3002;
}
 
server {
    listen 4000 ssl;
    proxy_pass btc-rpc-explorer;
}
$SU ln \
    -s \
    ../streams-available/btc-rpc-explorer-reverse-proxy.conf \
    /etc/nginx/streams-enabled/btc-rpc-explorer-reverse-proxy.conf
  • Test and reload NGINX configuration
$SU nginx -t
$SU rc-service nginx restart
 
  • Configure the firewall to allow incoming HTTPS requests
$SU ufw allow 4000/tcp comment 'allow BTC RPC Explorer SSL'

Modify node flags

printf "%s\n" \
    "export npm_config_cache=\"./npm-cache\"" \
    "export npm_config_devdir=\"./.gyp\"" \
    | $SU tee -a /etc/profile.d/node.sh
. /etc/profile.d/node.sh

Installation

BTC RPC Explorer (opens in a new tab) provides a lightweight and easy to use web interface to accomplish just that. It's a database-free, self-hosted Bitcoin blockchain explorer, querying Bitcoin client and Electrum server via RPC.

Download source code

We get the latest release of the BTC RPC Explorer source code and install it.

  • Download the source code for the latest BTC RPC Explorer release. You can check the release page (opens in a new tab) to see if a newer release is available. Other releases might not have been properly tested with the rest of the MicroBolt configuration, though.
cd /tmp
VERSION=3.4.0
git clone --branch v$VERSION https://github.com/janoside/btc-rpc-explorer.git && cd btc-rpc-explorer

Signature check

wget -qO- https://github.com/janoside.gpg | gpg --import
git verify-commit v$VERSION

Configure, patch and install

sed '/"node_modules\/sharp": {/,+21{d}; /sharp/d' npm-shrinkwrap.json > _
mv -f _ npm-shrinkwrap.json
  • Install all dependencies using the Node Package Manager (NPM).
npm install zeromq@6.0.0-beta.19
npm audit fix 

Installation can take some time, up to 20 minutes. There might be a lot of confusing output, but if you see something similar to the following, the installation was successful:

output
up to date, audited 621 packages in 3s

93 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
  • Make it a global permanent installation
$SU install -D -m 0660 -o btc-rpc-explorer -g btc-rpc-explorer ./.env-sample /etc/btc-rpc-explorer/.env
$SU mv -f /tmp/btc-rpc-explorer /var/lib/
$SU ln -s /var/lib/btc-rpc-explorer /usr/lib/node_modules/btc-rpc-explorer
$SU ln -s ../lib/node_modules/btc-rpc-explorer/bin/cli.js /usr/bin/btc-rpc-explorer

Configuration

  • Activate any setting by removing the # at the beginning of the line.
$EDITOR /etc/btc-rpc-explorer/.env
/etc/btc-rpc-explorer/.env
[...]
BTCEXP_BITCOIND_HOST=127.0.0.1
[...]
BTCEXP_BITCOIND_PORT=8332
[...]
BTCEXP_BITCOIND_COOKIE=/var/lib/bitcoind/.cookie
[...]
BTCEXP_ADDRESS_API=electrum
[...]
BTCEXP_ELECTRUM_SERVERS=tcp://127.0.0.1:50001
[...]
BTCEXP_SLOW_DEVICE_MODE=false
[...]
BTCEXP_UI_THEME={dark|light} # Choose one
[...]
Slow device mode
/etc/btc-rpc-explorer/.env
[...]
BTCEXP_BITCOIND_RPC_TIMEOUT=10000
[...]
BTCEXP_SLOW_DEVICE_MODE=true
[...]
Privacy mode
  • More information mode, including Bitcoin exchange rates:
/etc/btc-rpc-explorer/.env
[...]
BTCEXP_PRIVACY_MODE=false
[...]
BTCEXP_NO_RATES=false
[...]
  • More privacy mode, no external queries:
/etc/btc-rpc-explorer/.env
[...]
BTCEXP_PRIVACY_MODE=true
[...]
BTCEXP_NO_RATES=true
[...]
Security mode
  • You can add password protection to the web interface. Simply add password [D] for the following option, for which the browser will then prompt you. You can enter any user name; only the password is checked.
/etc/btc-rpc-explorer/.env
[...]
BTCEXP_DEMO=true
[...]
BTCEXP_BASIC_AUTH_PASSWORD=YourPassword[D]
[...]
Remote access over Tor

To use your blockchain explorer when you're on the go, you can easily create a Tor hidden service on the MicroBolt and accessing the BTC RPC Explorer with the Tor browser from any device.

  • Add the following three lines in the "location-hidden services" section in the torrc file.
$SU $EDITOR /etc/tor/torrc
/etc/tor/torrc
# Hidden Service BTC RPC Explorer
HiddenServiceDir /var/lib/tor/btc-rpc-explorer/
HiddenServiceVersion 3
HiddenServicePoWDefensesEnabled 1
HiddenServicePort 80 127.0.0.1:4000
  • Reload Tor configuration and get your connection address.
$SU rc-service tor reload
$SU cat /var/lib/tor/btc-rpc-explorer/hostname
output
abcdefg..............xyz.onion
  • You should now be able to connect to your BTC RPC Explorer remotely via Tor using your hostname and port 4000

Autostart on boot

Now we'll make sure our blockchain explorer starts as a service on the computer so that it's always running.

  • Create the BTC RPC Explorer init.d unit and copy/paste the following configuration. Save and exit.
$SU $EDITOR /etc/init.d/btc-rpc-explorer
/etc/init.d/btc-rpc-explorer
#!/sbin/openrc-run
 
: ${BTCRPCEXPL_CONFIGFILE:=/etc/btc-rpc-explorer/.env}
: ${BTCRPCEXPL_DATADIR:=/var/lib/btc-rpc-explorer}
: ${BTCRPCEXPL_LOGDIR:=/var/log/btc-rpc-explorer}
: ${BTCRPCEXPL_USER:=btc-rpc-explorer}
: ${BTCRPCEXPL_GROUP:=btc-rpc-explorer}
: ${BTCRPCEXPL_BIN:=/usr/bin/btc-rpc-explorer}
: ${BTCRPCEXPL_OPTS=${BTCRPCEXPL_OPTS}}
: ${BTCRPCEXPL_SIGTERM_TIMEOUT:=600}
 
BTCRPCEXPL_PIDDIR="/run/btc-rpc-explorer"
 
name="BTC RPC Explorer"
description="Simple, database-free Bitcoin blockchain explorer, via RPC to Bitcoin Core"
 
directory="${BTCRPCEXPL_DATADIR}"
required_files="${BTCRPCEXPL_CONFIGFILE}"
pidfile="${BTCRPCEXPL_PIDDIR}/${SVCNAME}.pid"
retry="${BTCRPCEXPL_SIGTERM_TIMEOUT}"
 
command="${BTCRPCEXPL_BIN}"
command_args="${BTCRPCEXPL_OPTS}"
command_user="${BTCRPCEXPL_USER}:${BTCRPCEXPL_GROUP}"
command_background="true"
 
start_stop_daemon_args="--stdout ${BTCRPCEXPL_LOGDIR}/debug.log
                        --stderr ${BTCRPCEXPL_LOGDIR}/debug.log"
 
depend() {
    need bitcoind
 
    if service_started fulcrum; then
        need fulcrum
    else
        need electrs
    fi
}
 
start_pre() {
    checkpath --file      --mode 0660 --owner "${command_user}" "${BTCRPCEXPL_CONFIGFILE}"
    checkpath --directory --mode 0750 --owner "${command_user}" "${BTCRPCEXPL_DATADIR}"
    checkpath --directory --mode 0755 --owner "${command_user}" "${BTCRPCEXPL_LOGDIR}"
    checkpath --directory --mode 0755 --owner "${command_user}" "${BTCRPCEXPL_PIDDIR}"
    checkconfig
}
 
checkconfig() {
    if ! grep -qs '^BTCEXP_BITCOIND_COOKIE=' "${BTCRPCEXPL_CONFIGFILE}"
    then
        eerror ""
        eerror "ERROR: You must set a BTCEXP_BITCOIND_COOKIE path to run"
        eerror "BTC RPC Explorer."
        eerror "The setting must appear in ${BTCRPCEXPL_CONFIGFILE}"
        eerror ""
        return 1
    fi
}
  • Enable execution permission
$SU chmod +x /etc/init.d/btc-rpc-explorer

Enable logrotate

  • Enter the complete next configuration. Save and exit
$SU $EDITOR /etc/logrotate.d/btc-rpc-explorer
/etc/logrotate.d/btc-rpc-explorer
/var/log/btc-rpc-explorer/*.log {
    weekly
    missingok
    rotate 104
    compress
    delaycompress
    notifempty
    create 0640 btc-rpc-explorer btc-rpc-explorer
    sharedscripts
    postrotate
        killall -HUP `cat /run/btc-rpc-explorer/btc-rpc-explorer.pid`
    endscript
}
  • Test
$SU logrotate /etc/logrotate.d/btc-rpc-explorer --debug

Enable and start BTC RPC Explorer

$SU rc-update add btc-rpc-explorer
$SU rc-service btc-rpc-explorer start
 
  • Check the log to see BTC RPC Explorer output. Exit with Ctrl-C
tail -f /var/log/btc-rpc-explorer/debug.log

For the future: BTC RPC Explorer update

Follow again Blockchain explorer page replacing the environment variable VERSION=x.xx value for the latest if it has not been already changed in this guide.

$SU $EDITOR /etc/btc-rpc-explorer/.env
  • Restart the service to apply the changes
$SU rc-service btc-rpc-explorer restart