Alephium's explorer backend is an indexer that provides a RESTful API to query the Alephium blockchain.
It serves https://explorer.alephium.org/ as well as our wallets.
- Java (11 or 17 is recommended)
- PostgreSQL
- A running full node
You need to have Postgresql and sbt installed in your system.
- Start the
postgresql
service. - Login to the PostgreSQL shell with the default
postgres
user:psql postgres # or `psql -U postgres` depending on your OS
- Ensure that the
postgres
role exists, and if not, create it. List all roles:Createpostgres=# \du
postgres
role:postgres=# CREATE ROLE postgres WITH LOGIN;
- Then, create the database:
postgres=# CREATE DATABASE explorer;
sbt app/run
sbt app/assembly
The resulting assembly file will appear in app/target/scala-2.13/
directory.
Download the lastest jar in our release page
Run it with:
java -jar explorer-backend-x.x.x.jar
Configuration file at /app/src/main/resources/application.conf
can be customized using environment variables
Everything can be overridden in two ways:
You can change the config in the ~/.alephium-explorer-backend/user.conf
file. e.g:
alephium {
explorer {
port = 9191 //Change default 9090 port
}
}
Every value has a corresponding environment variable, you can find all of them in the application.conf. e.g:
export EXPLORER_PORT=9191
Syncing all data from scratch can take a while, you can choose to start from a snapshot instead.
Alephium archives repository contains the snapshots for explorer backend database. The snapshot can be loaded in the postgresql database of the explorer-backend at the first run, using the command below.
- Make sure to use the network you want to load the snapshot for, and the correct database name and user.
- The database must be created before running the command and must be empty.
alephium_network=mainnet
pg_user=postgres
database=explorer
curl -L $(curl -L -s https://archives.alephium.org/archives/${alephium_network}/explorer-db/_latest.txt) | gunzip -c | psql -U $pg_user -d $database
Hash strings are stored as bytea. To query a hash string in
SQL use the Postgres function decode
which converts it to bytea
.
select *
from "utransactions"
where "hash" = decode('f25f43b7fb13b1ec5f1a2d3acd1bebb9d27143cdc4586725162b9d88301b9bd7', 'hex');
There are two ways to configure the application:
Every value in application.conf file can be overridden by an environment variable.
export BLOCKFLOW_NETWORK_ID = 1
export DB_NAME = "testnet"
The same way it's done in our full node, you can override the application.conf file by creating a user.conf
file in the EXPLORER_HOME
folder, which default to ~/.alephium-explorer-backend
.
alephium.blockflow.network-id = 1
db.db.name = "testnet"
The benchmark database (set via dbName) should exist:
CREATE DATABASE benchmarks;
Update the time
value in the following annotation
in DBBenchmark to set the benchmark
run duration:
@Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MINUTES)
Execute the following sbt
commands to run JMH benchmarks
sbt benchmark/jmh:run
The tests are using the Postgresql database and the default postgres
table.
sbt test
To generate scala-doc run: sbt unidoc
To reference external libraries in scala-docs make sure the library is recognised by adding an apiMapping
.
See scalaDocsAPIMapping
in build.sbt
file as a reference for creating this apiMapping
for an external library.
def myLibraryAPIMapping(classPath: Classpath, scalaVersion: String): (sbt.File, sbt.URL) =
??? //follow `scalaDocsAPIMapping` in build.sbt
//add the apiMapping to the project that depends on `myLibrary`
apiMappings ++=
Map(
myLibraryAPIMapping(
classPath = (Compile / fullClasspath).value,
scalaVersion = scalaVersion.value
)
)