See the full GitHub Project Code Repository
This developer guide will walk you through setting up an indexer, to query any ERC20 contract on the Berachain network using a GraphQL API, all with Envio.
This guide analyzes all WETH token "approval" and "transfer" event logs emitted by the WETH contract to gain real-time insights into metrics such as token holders, balances, and transfers of the WETH token. For this guide, let's analyze the top ten accounts with the largest WETH holdings, by querying the balance of token holders.
Before beginning, make sure you have the following installed or set up on your computer beforehand.
Let's start by initializing the indexer and generating a boilerplate to index all events emitted by the WETH ERC20 token contract on Berachain.
This is the WETH contract address: 0x8239FBb3e3D0C2cDFd7888D8aF7701240Ac4DcA4.
-
Open your terminal in a preferred directory and run the command
envio init. -
Name your indexer anything you’d like (e.g.
weth-berachain-indexer), and specify a folder name (e.g.weth-berachain-indexer.) -
Choose a preferred language, select
Template, and then selectErc20.
Note: Indexers on Envio can be written in JavaScript, TypeScript, or ReScript. For this demonstration, we’ve chosen to use TypeScript as the preferred language.
A project template is generated with all the required files to run your indexer.
Let's take a look at the files generated by Envio in our source-code editor, in this example, we’re using VS Code (Visual Code Studio).
- config.yaml
This file defines the network, start block, contract address, and events we want to index on Berachain.
Replace the placeholder values for network, start block and contract address with the correct values, i.e.
- Network Id = 80085
- Start Block = 0
- Contract Address = 0x8239FBb3e3D0C2cDFd7888D8aF7701240Ac4DcA4
- Schema.graphql
This file saves and defines the data structures for selected events, such as the Approval event.
- event-handler
This file defines what happens when an event is emitted and saves what code is going to run, allowing customization in data handling.
Now, let's run our indexer locally by running envio dev command.
Your browser would have opened a local Hasura console at http://localhost:8080/console. Let’s explore the indexed data.
- Head over to the Hasura console, type in the admin-secret password
testing, and navigate to “Data” in the above column to explore the data. For example, you can:
- View "events_sync_state" table to see which block number you are on to monitor the indexing progress.
- View the "chain_metadata" table to see the block height of the chain.
- View the "raw_events" table to see all events being indexed.
If you view the "Account" table, you will see a column called "balance".
- Let's analyze this data, by clicking “API” in the above column to access the GraphQL endpoint to query real-time data. From there you can run a query to explore details such as holders and their respective balances of the WETH ERC-20 token.
The full github code repository can be found in the guides section of this repository under Index ERC20 Contract Using Envio.


