Skip to content

zenchain-protocol/zentrace-backend

 
 

Repository files navigation

Zentrace Backend

Zentrace is a comprehensive block explorer and analytics platform tailored for the Zenchain blockchain. Originating as a fork from Blockscout, Zentrace has undergone significant enhancements to improve functionality and ease of deployment across various operating systems.

Zentrace ecosystem consists of the following components:

Development environment configuration

The process of setting up the development environment for Zentrace Backend, which is built using Elixir, differs depending on the operating system in use. This tutorial is designed to guide you through the preparation of your development environment, tailored to each of these operating systems.

Dependencies

To successfully compile your code, it's essential to first install the required dependencies, with the installation process varying depending on your operating system.

Git

Git is needed to get code from repositories.

Linux/WSL (Windows Subsystem for Linux)

Follow the instructions based on your Linux distribution (WSL by default installs Ubuntu) https://git-scm.com/download/linux

MacOS

Install Homebrew https://brew.sh and execute the following command:

brew install git

Windows

Download and execute the installer based on your architecture https://git-scm.com/download/win

Asdf

Linux/WSL (Windows Subsystem for Linux)

curl package is needed, you can install it executing the following command (Ubuntu as reference):

sudo apt install -y curl

clone the Asdf repository with the following command:

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0

edit the ~/.bashrc file appending the following lines:

. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"

install needed plugins executing the following commands:

asdf plugin add erlang
asdf plugin add elixir
asdf plugin add nodejs

MacOS

curl and coreutils packages are needed, you can install them executing the following commands:

brew install coreutils curl

clone the Asdf repository with the following command:

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0

create/edit the ~/.bash_profile file appending the following lines:

. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"

install needed plugins executing the following commands:

asdf plugin add erlang
asdf plugin add elixir
asdf plugin add nodejs

PostgreSQL

Linux/WSL (Windows Subsystem for Linux)

Install PostgreSQL with the following command:

sudo apt install postgresql

alter postgres password:

sudo -u postgres psql template1
ALTER USER postgres with encrypted password 'postgres';

create the environment variable used by the backend as connection string:

export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/zentrace

MacOS

Install PostgreSQL with the following command:

brew install postgresql@15 libpq
brew link --force libpq

alter MAC_USER password:

ALTER USER MAC_USER with encrypted password 'postgres';

create the environment variable used by the backend as connection string:

export DATABASE_URL=postgresql://MAC_USER:postgres@localhost:5432/zentrace

Additional dependencies

Linux/WSL (Windows Subsystem for Linux)

Execute the following command (Ubuntu as reference):

sudo apt install -y libssl-dev make automake autoconf libncurses5-dev gcc g++ inotify-tools

How to compile

Create a new folder, open it in the terminal and execute:

git clone https://github.com/zenchain-protocol/zentrace-backend

Open zentrace-backend folder and execute:

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

Docker based development

You can also build and run all within Docker directly.

Edit the following environment variables:

and then execute:

All

cd docker-compose
docker compose up -d

Only backend

cd docker-compose
docker compose -f external-frontend.yml up -d

starts containers and starts listening using the port 80.

Start the application locally

Generate the database structure with the following command:

mix do ecto.create, ecto.migrate

Generate a new authentication encryption key:

mix phx.gen.secret

set the key into the SECRET_KEY_BASE environment variable:

export SECRET_KEY_BASE=KEY

Install Node.js packages:

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

Generate local SSL certificate for development:

cd apps/block_scout_web
mix phx.gen.cert zentrace zentrace.local

Edit common-backend.env variables and execute the following command to export all:

Linux/WSL (Windows Subsystem for Linux)

export $(grep -v '^#' ./docker-compose/envs/common-backend.env | xargs -d '\n')

MacOS

export $(grep -v '^#' ./docker-compose/envs/common-backend.env | xargs -0)

You can now start the application for development with the following command:

mix phx.server

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Elixir 83.7%
  • HTML 5.7%
  • Solidity 4.0%
  • SCSS 3.3%
  • JavaScript 3.2%
  • Shell 0.1%