This tutorial will take you through the process of indexing HRC20 token transfers on the Harmony using Envio.
The goal of this tutorial is to easily create an indexer that tracks and analyzes all LINK token transfers on Harmony by extracting the Transfer (index_topic_1 address from, index_topic_2 address to, uint256 value)
logs emitted by the LINK contract. This enables real-time insights into metrics such as the largest LINK token transfers.
Before we start indexing, you'll need to make sure you have the prerequisites installed.
Now that you’re all set up and have installed the prerequisite packages required, let’s jump into the practical steps of initializing the indexer and generating a boilerplate index to index the largest LINK token transfers on Harmony.
Open your terminal in an empty repository and run the command envio init
.
Name your indexer anything you’d like (e.g. harmony-hrc20-transfer
).
Choose a preferred language, select Contract Import
, and import from Local ABI
.
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.
Note: For the Contract Import feature, the
Block Explorer
option currently only supports networks with Etherscan. If the network doesn't have Etherscan, you can proceed using theLocal ABI
option. ChoosingLocal ABI
option will allow you to point to a JSON file containing the smart contract ABI. The Contract Import process will then populate the required files from the ABI.
Head over to the Harmony Explorer, and save the ABI code from the LINK smart contract address as a file in the current working directory. For this demonstration, we've chosen to name the ABI file "abi.json". Specify the directory of JSON file containing ABI, for example abi.json
.
LINK Token Contract address: 0x218532a12a389a4a92fc0c5fb22901d1c19198aa
Select the events you would like to index. In this case, we’ll be indexing the transfer
event.
Note: Multiple events can be selected and indexed at the same time.
Specify the chain the contract is deployed on, the name of the contract, and the address.
Note: If you are using a proxy contract with an implementation, the address should be for the proxy.
Finally, review the configuration and select I’m finished
to start generating the indexer.
Now, let's run our indexer locally by running envio dev
command.
Once that’s all done we can take a peek 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 Harmony.
Schema.graphql
This file saves and defines the data structures for selected events, such as the transfer
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.
Well done, now let’s explore the indexed data. Your browser would have opened a local Hasura console at http://localhost:8080/console
Head over to the Hasura console, type in the admin-secret password testing
, and click “API” in the above column to access the GraphQL endpoint to query real-time data.
Navigate to “Data” in the above column to monitor the indexing progress on Harmony through the events sync state table to see which block number you are on.
Explore the "LINK_Transfer" table to explore details such as amount, senders, recipients and values.
Finally let’s analyze some events. Simply head back to “API” in the above column. From there you can run a query-specific event, in this example "LINK_Transfer" to explore details such as amounts, senders, recipients and values.
Once you have selected your desired events run the query by clicking the play button ( ▶️) to gain access to the real-time indexed data.
For example:
Let’s look at getting 10 Link_Transfer
events, and order them by the amount we would like to appear first (in this case: desc = largest amount), who it’s from, who it’s to, and the value being transferred.
You can now run queries to explore specific events, such as the largest LINK transfers.
If you want to index more than just transfer
events, such as holders and balances, you can select Erc20
template option after running envio init
command.