Blockscout

Overview

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.

Environment

  • Operating System: Ubuntu Server 20.04 LTS download link with sudo permissions

  • Server Hardware: 2CPU / 4GB RAM / 50GB HDD (LVM)

  • Database Server: Dedicated server with 2 CPU / 4GB RAM / 30GB SSD / PostresSQL 13.4

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

:::info DISCLAMER 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. :::

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 & upgrade system

sudo apt update && sudo apt -y upgrade

Install erlang and its dependancies from default packages

Add erlang repos

Add NodeJS repo

Install Rust

Install specific versions of Erlang and Elixir

Install NodeJS

Install Cargo

Install other dependancies

Optionaly install postgresql client to check your db connection

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

Set env vars

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:

Otherwise you might see an error like this:

If this is the case these docs might help you.

:::info DB Connection 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. :::

Part 3 - clone and compile Blockscout

Now we finaly get to start the Blockscout installation.

Clone Blockscout repo

Compile

Cd into clone directory and start compiling

Migrate databases

:::info This part will fail if you didn't setup 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. :::

Install npm dependancies and compile frontend assets

You need to change directory to the folder which contains frontend assets.

:::info Be patient 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 :::

Build static assets

For this step you need to return to the root of your Blockscout clone folder.

Generate self-signed certificates

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

Edit service file

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

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

Enable starting service on system boot

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.

Create env vars file which will be used by Blockscout service

:::info Use the same environment variables as you've set in Part 2. :::

Save the file and exit.

Finaly 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:

To check service output:

You can check if there are some new listening ports:

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

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://<host_ip>:4000 or https://<host_ip>:4001

Final thoughts

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 sould also think about database and instance scalability, depending on your use case.

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

Last updated