zkSync Era Block Explorer Worker
is an indexer service for zkSync Era blockchain data. It retrieves aggregated data from the Data Fetcher via HTTP and also directly from the blockchain using zkSync Era JSON-RPC API, processes it and saves into the database in a way that makes it easy to read by the Block Explorer API.
$ npm install
- Create
.env
file in theworker
package folder and copy paste.env.example
content in there.
cp .env.example .env
- In order to tell the service where to get the blockchain data from set the value of the
BLOCKCHAIN_RPC_URL
env var to your blockchain RPC API URL. For zkSync Era testnet it can be set tohttps://zksync2-testnet.zksync.dev
. For zkSync Era mainnet -https://zksync2-mainnet.zksync.io
. - To retrieve aggregated blockchain data for a certain block, the Worker service calls the Data Fetcher service via HTTP. To specify Data Fetcher URL use
DATA_FETCHER_URL
env variable. By default, it is set tohttp://localhost:3040
which is a default value for the local environment. - Set up env variables for Postgres database connection. By default it points to
localhost:5432
and database name isblock-explorer
. You need to have a running Postgres server, set the following env variables to point the service to your database:DATABASE_HOST
DATABASE_USER
DATABASE_PASSWORD
DATABASE_NAME
DATABASE_CONNECTION_IDLE_TIMEOUT_MS
DATABASE_CONNECTION_POOL_SIZE
The service doesn't create database automatically, you can create database by running the following command:
$ npm run db:create
# development
$ npm run dev
# watch mode
$ npm run dev:watch
# debug mode
$ npm run dev:debug
# production mode
$ npm run start
# unit tests
$ npm run test
# unit tests debug mode
$ npm run test:debug
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
Run npm run lint
to make sure the code base follows configured linter rules.
Changes to the DB are stored as migrations scripts in src/migrations
folder and are automatically executed on the application start.
We use code first approach for managing DB schema so desired schema changes should be first applied to the Entity classes and then migrations scripts can be generated running the following command: migration:generate
.
Example:
npm run migration:generate -name=AddStatusColumnToTxTable
a new migration with the specified name and all schema changes will be generated in src/migration
folder. Always check generated migrations to confirm that they have everything you intended.
Sometimes you need to write a manual migration script not generated based on any schema changes. For instance, to run a script to update some records. In this case use migration:create
to create an empty migration.
Example:
npm run migration:create -name=UpdateTxsFee
this command will simply create an empty migration where the custom migration logic can be added.
If a token (Token A) retrieved from the Coingecko API lacks a price, follow these steps:
- Find another token (Token B) which have price in Coingecko API and share a similar price with Token A.
- Use token B's Coingecko API ID in the
id
field. - In the
platforms
field, use "extra" as the key and input Token A's address.
If a token (Token A) on a specific blockchain lacks a price on the Coingecko API but has a price on another blockchain, follow these steps:
- Utilize Token A's Coingecko API ID in the
id
field. - In the
platforms
field, use the name of the blockchain where Token A lacks a price and input Token A's address.
Also, in the chain
field, make reference to the Coingecko platform API: https://docs.coingecko.com/v3.0.1/reference/asset-platforms-list
If a token (Token A) is not listed on Coingecko and displays an incorrect logo in the explorer, modify the extraTokenAttribute.json file params:
- name:Utilize the token symbol along with the chain name.
- address: Provide the L1 or L2 token contract address.
- image: Enter the correct token logo URL.
- market_ap: Avoid using 0; instead, use any other number such as 1, to prevent displaying the market cap of a particular Coingecko token used for price reference.