Blockscout

BlockScout It's a Elixir Applications, Allows users to search the Ethereum network (Including all forks and side chains) Trading on the Internet, View accounts and balances and validate smart contracts.

Overview

This guide goes into details on how to compile and deploy Blockscout instance to work under ubuntu. Blockscout has its own documentation, but this guide focuses on simple but detailed step-by-step instructions on how to setup Blockscout instance.

Environment

  • Operating System: Ubuntu 18.04.6 LTS (GNU/Linux 4.15.0-177-generic x86_64)
  • Server Hardware: ProLiant DL585 G7
  • Database Server: PostgreSQL 10.19 (Ubuntu 10.19-0ubuntu0.18.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, 64-bit

DB Server

The requirement for following this guide is to have a database server ready, database and db user configured. This guide will not go into details on how to deploy and configure PosgreSQL server. There are plenty of guides on now to do this, for example DigitalOcean Guide

$ sudo apt-get update
$ sudo apt install postgresql postgresql-contrib
$ sudo -u postgres psql -c "SELECT version();"

Blockscout Deployment Procedure

Part 1 - install dependancies

Before we start we need to make sure we have all the binaries installed that the blockscout is dependent on.

Update system

$ sudo apt update

Install erlang and its dependancies from default packages

$ sudo apt -y install erlang
$ erl --version

Add erlang repos

$ cd ~   #go to your home dir
$ wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb   #download deb
$ wget https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc   #download key
$ sudo dpkg -i erlang-solutions_2.0_all.deb   #install repo
$ sudo apt-key add erlang_solutions.asc   #install key
$ rm erlang-solutions_2.0_all.deb   #remove deb
$ rm erlang_solutions.asc    #remove key

Install specific versions of Erlang and Elixir

$ sudo apt -y install esl-erlang=1:24.* elixir=1.12.*

Add NodeJS repo

$ sudo curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

Install NodeJS

$ sudo apt -y install nodejs
$ node --version

Install Rust

$ sudo curl https://sh.rustup.rs -sSf | sh -s -- -y
$ rustc --version

Install Cargo

$ sudo apt install cargo

Install other dependancies

$ sudo apt -y install automake libtool inotify-tools gcc libgmp-dev make g++ git
$ make --version
$ gcc --version

Part 2 - set environment variables

We need to set the environment variables, before we begin with Blockscout compilation. In this guide we’ll set only the basic minimum to get it working. Full list of variables that can be set you can find here

export SECRET_KEY_BASE=VTIB3uHDNbvrY0+60ZWgUoUBKDn9ppLR8MI4CpRz4/qLyEFs54ktJfaNT6Z221No
export ETHEREUM_JSONRPC_VARIANT=geth
export ETHEREUM_JSONRPC_HTTP_URL=http://192.168.77.70:8545
export ETHEREUM_JSONRPC_TRACE_URL=http://192.168.77.70:8545
export ETHEREUM_JSONRPC_WS_URL=ws://192.168.77.70:8546
export DATABASE_URL=postgresq://peware:123456@192.168.77.80:5432/blockscout
export COIN=NBAI

Part 3 - clone and compile Blockscout

Clone Blockscout repo

$ cd ~
$ git clone https://github.com/poanetwork/blockscout.git

Compile

$ mix local.hex --force
$ mix do deps.get, local.rebar --force, deps.compile
$ mix compile

Migrate databases

$ mix do ecto.create, ecto.migrate

Install npm dependancies and compile frontend assets

$ cd apps/block_scout_web/assets; npm install && node_modules/webpack/bin/webpack.js --mode production; cd -
$ cd apps/explorer && npm install; cd -

Part 4 - create and run Blockscout service

In this part we need to setup a system service as we want Blockscout to run in the backround and persist after system reboot.

Create service file

$ sudo touch /etc/systemd/system/blockscout.service

Edit service file

Use your favorite linux text editor to edit this file and configure the service.

$ sudo vim /etc/systemd/system/blockscout.service

The contents of the explorer.service file should look like this:

[Unit]
Description=Blockscout Server
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=peware
StandardOutput=syslog
StandardError=syslog
WorkingDirectory=/usr/local/blockscout
ExecStart=/usr/bin/mix phx.server
EnvironmentFile=/usr/local/blockscout/env_vars.env

[Install]
WantedBy=multi-user.target

Enable starting service on system boot

$ sudo systemctl daemon-reload
$ sudo systemctl enable blockscout.service

Move your Blockscout clone folder to system wide location

Blockscout service needs to have access to the folder you’ve cloned from Blockscout repo and compiled all the assets.

$ sudo mv ~/blockscout /usr/local

Create env vars file which will be used by Blockscout service

$ sudo touch /usr/local/blockscout/env_vars.env
$ sudo vi /usr/local/blockscout/env_vars.env

Use the same environment variables as you’ve set in Part 2.

SECRET_KEY_BASE=VTIB3uHDNbvrY0+60ZWgUoUBKDn9ppLR8MI4CpRz4/qLyEFs54ktJfaNT6Z221No
ETHEREUM_JSONRPC_VARIANT=geth
ETHEREUM_JSONRPC_HTTP_URL=http://192.168.77.70:8545
ETHEREUM_JSONRPC_TRACE_URL=http://192.168.77.70:8545
ETHEREUM_JSONRPC_WS_URL=ws://192.168.77.70:8546
DATABASE_URL=postgresql://peware:123456@192.168.77.64:5432/blockscout
COIN=NBAI
HEART_COMMAND="systemctl start blockscout.service"

Save the file and exit.

Finaly start Blockscout service

$ sudo systemctl start blockscout.service

Part 5 - test out the functionality of your Blockscout instance

Now all thats left to do is to check if Blockscout service is running. Check service status with:

$ sudo systemctl status blockscout.service

To check service output:

$ sudo journalctl -e -u blockscout.service

You can check if there are some new listening ports:

$ sudo apt install net-tools   #if netstat is not installed
$ sudo netstat -tulpn

You should get a list of listening ports and on the list there should be something like this:

tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 28252/postgres

tcp 0 0 0.0.0.0:4000 0.0.0.0:* LISTEN 42258/beam.smp

tcp 0 0 0.0.0.0:4001 0.0.0.0:* LISTEN 42258/beam.smp

Blockscout web service runs by default on ports 4000(http) and 4001(https). If everythig is ok, you should be able to access the Blockscout web portal with http://192.168.77.64:4000 or https://192.168.77.64:4001

Final thoughts

You should definitely checkout the official Blockscout documentation as there a lot of customisation options.

Note

$ cat /proc/sys/fs/inotify/max_user_watches

Temporarily:

$ sudo sysctl fs.inotify.max_user_watches=524288

Permanently (more detailed info):

put fs.inotify.max_user_watches=524288 into your sysctl settings. Depending on your system they might be in one of the following places:

$ vi /etc/sysctl.conf

you may wish to reload the sysctl settings to avoid a reboot: sysctl -p

comments powered by Disqus