Blockscout Explorer Install
This guide goes into details on how to compile and deploy Blockscout instance to work with Polygon-Edge. Blockscout has its own documentation, but this guide focuses on simple but detailed step-by-step instructions on how to setup Blockscout instance.
- Server Hardware: 8CPU / 16GB RAM / 50GB HDD (LVM)
- Database Server: Dedicated server with 2 CPU / 4GB RAM / 100GB SSD / PostgreSQL 13.4
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 PostgreSQL server. There are plenty of guides on now to do this, for example DigitalOcean Guide
This guide is meant only to help you to get Blockscout up and running on a single instance which is not ideal production setup. For production, you'll probably want to introduce reverse proxy, load balancer, scalability options, etc. into the architecture.
Before we start we need to make sure we have all the binaries installed that the blockscout is dependent on.
sudo apt -y update && sudo apt -y upgrade
# go to your home dir
# download deb
# download key
# install repo
sudo dpkg -i erlang-solutions_2.0_all.deb
# install key
sudo apt-key add erlang_solutions.asc
# remove deb
# remove key
sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo curl https://sh.rustup.rs -sSf | sh -s -- -y
sudo apt -y install esl-erlang=1:24.*
The version of Elixir must be
1.13. If we try and install this version from the official repo, the
erlangwill update to
Erlang/OTP 25and we do not want that. Because of this, we need to install the specific precompiled
elixirversion from GitHub releases page.
sudo unzip -d /usr/local/elixir/Precompiled.zip
Now we need to properly set up
sudo ln -s /usr/local/elixir/bin/elixir /usr/local/bin/elixir
sudo ln -s /usr/local/elixir/bin/mix /usr/local/bin/mix
sudo ln -s /usr/local/elixir/bin/iex /usr/local/bin/iex
sudo ln -s /usr/local/elixir/bin/elixirc /usr/local/bin/elixirc
erlangare properly installed by running
elixir -v. This should be the output:
Erlang/OTP 24 [erts-12.3.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]Elixir 1.13.4 (compiled with Erlang/OTP 22)
Erlang/OTPmust be version
Elixirmust be version
1.13.*. If that is not the case, you will run into issues with compiling Blockscout and/or running it.
sudo apt -y install nodejs
sudo apt -y install cargo
sudo apt -y install automake libtool inotify-tools gcc libgmp-dev make g++ git
sudo apt install -y postgresql-client
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
# postgresql connection example: DATABASE_URL=postgresql://blockscout:[email protected]:5432/blockscoutexport DATABASE_URL=postgresql://<db_user>:<db_pass>@<db_host>:<db_port>/<db_name> # db_name does not have to be existing database# we set these env vars to test the db connection with psqlexport PGPASSWORD=Passw0Rdexport PGUSER=blockscoutexport PGHOST=db.instance.localexport PGDATABASE=postgres # on AWS RDS postgres database is always created
Now test your DB connection with provided parameters. Since you've provided PG env vars, you should be able to connect to the database only by running:
If the database is configured correctly, you should see a psql prompt:
psql (12.9 (Ubuntu 12.9-0ubuntu0.20.04.1))SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)Type "help" for help.blockscout=>
Otherwise, you might see an error like this:
psql: error: FATAL: password authentication failed for user "blockscout"FATAL: password authentication failed for user "blockscout"
Make sure you've sorted out all db connection issues before proceeding to the next part. You'll need to provide superuser privileges to blockscout user.
Now we finally get to start the Blockscout installation.
git clone https://github.com/3LechesCake/blockscout
mix local.rebar --force
At the very last line, you should see a long string of random characters. This should be set as your
SECRET_KEY_BASEenvironment variable, before the next step. For example:
Cd into clone directory and start compiling
mix local.hex --force
mix do deps.get, local.rebar --force, deps.compile, compile
If you have deployed previously, remove static assets from the previous build mix phx.digest.clean.
This part will fail if you didn't set up your DB connection properly, you didn't provide, or you've defined wrong parameters at DATABASE_URL environment variable. The database user needs to have superuser privileges.
mix do ecto.create, ecto.migrate
If you need to drop the database first, run
mix do ecto.drop, ecto.create, ecto.migrate
You need to change directory to the folder which contains frontend assets.
sudo npm install
sudo node_modules/webpack/bin/webpack.js --mode production
Compilation of these assets can take a few minutes, and it will display no output. It can look like the process is stuck, but just be patient. When compile process is finished, it should output something like:
webpack 5.69.1 compiled with 3 warnings in 104942 ms
For this step you need to return to the root of your Blockscout clone folder.
sudo mix phx.digest
You can skip this step if you won't use
mix phx.gen.cert blockscout blockscout.local
The above command will generate and enable self-signed ssl certs, you need to replace them with real ones. You may use certbot (opens new window)(letsencrypt) to do it, don't forget to set user permissions and configure the file:
/path/to/blockscout/config/dev.exs, see example below:
\$ nano /path/to/blockscout/config/dev.exs
config :block_scout_web, BlockScoutWeb.Endpoint,
http: [port: 4000],
If using certbot, add cert renewal to crontab
- Add blockscout and blockscout.local to your
127.0.0.1 localhost blockscout blockscout.local
::1 localhost blockscout blockscout.local
In this part we need to set up a system service as we want Blockscout to run in the background and persist after system reboot.
sudo touch /etc/systemd/system/explorer.service
Use your favorite linux text editor to edit this file and configure the service.
sudo vi /etc/systemd/system/explorer.service
The contents of the explorer.service file should look like this:
sudo systemctl daemon-reload
sudo systemctl enable explorer.service
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
sudo touch /usr/local/blockscout/env_vars.env
# use your favorite text editor
sudo vi /usr/local/blockscout/env_vars.env
# env_vars.env file should hold these values ( adjusted for your environment )
# json-rpc API of the chain
# same as json-rpc API
# database connection from Step 2
# secret key base ETHEREUM_JSONRPC_WS_URL="ws://localhost:8545/ws"
# websocket API of the chainCHAIN_ID=93201
# chain idHEART_COMMAND="systemctl restart explorer"
# command used by blockscout to restart it self in case of failure
# this will be in html title
# logo location
# footer logo location
COIN="EDGE" # coin
COIN_NAME="EDGE Coin" # name of the coin
# disable block reward indexer as Polygon Edge doesn't support tracing
# disable pending transactions indexer as Polygon Edge doesn't support tracing
# disable internal transactions indexer as Polygon Edge doesn't support tracing
MIX_ENV="prod" # run in production mode
BLOCKSCOUT_PROTOCOL="http" # protocol to run blockscout web service on
PORT=4000 # port to run blockscout service on
DISABLE_EXCHANGE_RATES="true" # disable fetching of exchange rates
# the number of database connections
# the number of read-only database connections
# if protocol is set to http this should be false
# run HEARTH_COMMAND if heartbeat missing for this amount of seconds
# soft memory limit for indexer - depending on the size of the chain and the amount of RAM the server has
# disable trace_block query
# sanitize empty block in this batch size
SECRET_KEY_BASEyou've generated in Part 3.
Save the file and exit.
sudo systemctl start explorer.service
Now all that's left to do is to check if Blockscout service is running. Check service status with:
sudo systemctl status explorer.service
To check service output:
sudo journalctl -u explorer.service -f
You can check if there are some new listening ports:
# if netstat is not installed
sudo apt install net-tools
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 28142/postgrestcp 0 0 0.0.0.0:4000 0.0.0.0:* LISTEN 42148/beam.smp
Blockscout web service runs the port and protocol defined in env file. In this example it runs on
4000(http). If everything is ok, you should be able to access the Blockscout web portal with
For best performance, it is advisable to have a dedicated/local
polygon-edgefull archive non-validator node that will be used exclusively for Blockscout queries. The
json-rpcAPI of this node, doesn't need to be exposed publicly, as Blockscout runs all queries from the backend.
We've just deployed a single Blockscout instance, which works fine, but for production you should consider placing this instance behind a reverse proxy like Nginx. You should also think about database and instance scalability, depending on your use case.