# Indexing HRC20 with 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.

## Prerequisites

Before we start indexing, you'll need to make sure you have the [prerequisites](https://docs.envio.dev/docs/getting-started) installed.

## Initializing an Indexer

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.

1. Open your terminal in an empty repository and run the command `envio init`.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-64f6e889f70e4ac7cdfb5531a58ad40b040e09d9%2Fenvio-indexing-tutorial-init-1%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

2. Name your indexer anything you’d like (e.g. `harmony-hrc20-transfer`).

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-e317e0489fa4191bf7250c114958b5f1629a9753%2Fenvio-indexing-tutorial-init-2%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

3. 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 the `Local ABI` option. Choosing `Local 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.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-3b3741f781bdb65ee123f1cfe059c30fde595fce%2Fenvio-indexing-tutorial-init-3a.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-74db6a9b7d3ce859143a71e187d9926c03791d3f%2Fenvio-indexing-tutorial-init-3b.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-1eb89c94ae6393e6d6dd3281dbe6fab06a0daefb%2Fenvio-indexing-tutorial-init-3c.png?alt=media" alt=""><figcaption></figcaption></figure>

4. Head over to the [Harmony Explorer](https://explorer.harmony.one/), 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](https://explorer.harmony.one/address/0x218532a12a389a4a92fc0c5fb22901d1c19198aa)

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-42b5dd9d95cb866b7c9a08d7402eafff33d49fc1%2Fenvio-indexing-tutorial-init-4a.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-475710d87cc96b55ce497509776f941f56be4931%2Fenvio-indexing-tutorial-init-4b.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-8f3ae4b95ade62b4f9dacfb4322c97f3cfa123f0%2Fenvio-indexing-tutorial-init-4c.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-04fbddbde756bddd86d8720e75e06bd187dae454%2Fenvio-indexing-tutorial-init-4d.png?alt=media" alt=""><figcaption></figcaption></figure>

5. 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.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-e126314b50d137706827a765b057232d3c2d32fe%2Fenvio-indexing-tutorial-init-5.png?alt=media" alt=""><figcaption></figcaption></figure>

6. 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.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-9c0a04879ae9f645fe7454a8bb5f7f2a5f7be6f8%2Fenvio-indexing-tutorial-init-6.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-c38936b839493bb2221bef4c4bcc1f27715f1b9e%2Fenvio-indexing-tutorial-init-6b.png?alt=media" alt=""><figcaption></figcaption></figure>

7. Finally, review the configuration and select `I’m finished` to start generating the indexer.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-5ebed29781d60ab0bfb0271dfffa6f3e5cdb18f2%2Fenvio-indexing-tutorial-init-7.png?alt=media" alt=""><figcaption></figcaption></figure>

## Starting the Indexer

Now, let's run our indexer locally by running `envio dev` command.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-578140c0c476dd21c778756d1575e114f1fb33e9%2Fenvio-indexing-tutorial-dev-1.png?alt=media" alt=""><figcaption></figcaption></figure>

## Overview of Generated Code

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](https://code.visualstudio.com/) (Visual Code Studio).

1. **config.yaml**

This file defines the network, start block, contract address, and events we want to index on Harmony.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-0bc050212fc6a4a320b339b5f0db17d7b70fb301%2Fenvio-indexing-tutorial-code-config.png?alt=media" alt=""><figcaption></figcaption></figure>

2. **Schema.graphql**

This file saves and defines the data structures for selected events, such as the `transfer` event.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-5ecf51aaecb1a5e8e427d6050775a42d25e61834%2Fenvio-indexing-tutorial-code-schema.png?alt=media" alt=""><figcaption></figcaption></figure>

3. **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.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-63e339dc54c896fe690c5eada4b687792520c49f%2Fenvio-indexing-tutorial-code-handlers.png?alt=media" alt=""><figcaption></figcaption></figure>

## Exploring the Indexed Data

Well done, now let’s explore the indexed data. Your browser would have opened a local Hasura console at <http://localhost:8080/console>

1. 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.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-308791a8a7723fee3d161b7d6c3a9939a5334aa0%2Fenvio-indexing-tutorial-hasura-1.png?alt=media" alt=""><figcaption></figcaption></figure>

2. 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.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-15ec782ae0488ab487a24c83ae511fe48c21c5fc%2Fenvio-indexing-tutorial-hasura-2%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

3. Explore the "LINK\_Transfer" table to explore details such as amount, senders, recipients and values.

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-cc9567921ab7895b3a404c894515be8a26694096%2Fenvio-indexing-tutorial-hasura-3%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

4. 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.*

<figure><img src="https://3781397247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LlEOlYqEG_GKuO5Rehq%2Fuploads%2Fgit-blob-d152e386853730448972cd02af5838008ec74005%2Fenvio-indexing-tutorial-hasura-4.png?alt=media" alt=""><figcaption></figcaption></figure>

**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.
