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.
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
DISCLAIMER
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.
The version of Elixir must be 1.13. If we try and install this version from the official repo, the erlang will update to Erlang/OTP 25 and we do not want that.
Because of this, we need to install the specific precompiled elixir version from GitHub releases page.
Now we need to properly set up exlixir system binaries.
Check if elixir and erlang are properly installed by running elixir -v. This should be the output:
DANGER
Erlang/OTP must be version 24 and Elixir must be version 1.13.*.
If that is not the case, you will run into issues with compiling Blockscout and/or running it.
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
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:
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.
Generate secret key base to protect production build
At the very last line, you should see a long string of random characters.
This should be set as your SECRET_KEY_BASE environment variable, before the next step.
For example:
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.
If you need to drop the database first, run
Install npm dependencies and compile frontend assets
You need to change directory to the folder which contains frontend assets.
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
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:
If using certbot, add cert renewal to crontab
Add blockscout and blockscout.local to your /etc/hosts
If using Chrome, Enable chrome://flags/#allow-insecure-localhost
Part 5 - test out the functionality of your Blockscout instance
Now all that's 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 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 http://<host_ip>:4000.
For best performance, it is advisable to have a dedicated/local polygon-edge full archive non-validator node that will be used exclusively for Blockscout queries.
The json-rpc API 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.
You should definitely check out the official Blockscout documentation as there a lot of customisation options.
# 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
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 )
ETHEREUM_JSONRPC_HTTP_URL="localhost:8545"
# json-rpc API of the chain
ETHEREUM_JSONRPC_TRACE_URL="localhost:8545"
# same as json-rpc API
DATABASE_URL='postgresql://blockscout:[email protected]:5432/blockscout'
# database connection from Step 2
SECRET_KEY_BASE="912X3UlQ9p9yFEBD0JU+g27v43HLAYl38nQzJGvnQsir2pMlcGYtSeRY0sSdLkV/"
# 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
SUBNETWORK="Supertestnet POA"
# this will be in html title
LOGO="/images/polygon_edge_logo.svg"
# logo location
LOGO_FOOTER="/images/polygon_edge_logo.svg"
# footer logo location
COIN="EDGE" # coin
COIN_NAME="EDGE Coin" # name of the coin
INDEXER_DISABLE_BLOCK_REWARD_FETCHER="true"
# disable block reward indexer as Polygon Edge doesn't support tracing
INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER="true"
# disable pending transactions indexer as Polygon Edge doesn't support tracing
INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER="true"
# 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
POOL_SIZE=200
# the number of database connections
POOL_SIZE_API=300
# the number of read-only database connections
ECTO_USE_SSL="false"
# if protocol is set to http this should be false
HEART_BEAT_TIMEOUT=60
# run HEARTH_COMMAND if heartbeat missing for this amount of seconds
INDEXER_MEMORY_LIMIT="10Gb"
# soft memory limit for indexer - depending on the size of the chain and the amount of RAM the server has
FETCH_REWARDS_WAY="manual"
# disable trace_block query
INDEXER_EMPTY_BLOCKS_SANITIZER_BATCH_SIZE=1000
# sanitize empty block in this batch size
sudo systemctl start explorer.service
sudo systemctl status explorer.service
sudo journalctl -u explorer.service -f
# if netstat is not installed
sudo apt install net-tools
sudo netstat -tulpn