How to index ERC-20 transfers on Celo up to 1000x faster than RPC using Envio⚡

Envio
6 min readJun 28, 2024

--

Introduction

In this tutorial, we’ll explore how to use Envio’s modern indexing framework to index and monitor ERC-20 token transfers on the Celo Network, providing real-time insights into metrics such as the largest Celo Dollar (c.USD) transfers on Celo. The guide uses Envio’s No-code Quickstart, which is the quickest way to get going and the likely starting point for most developers developing a custom GraphQL for their application or use case.

What is Envio?

Envio is a feature-rich blockchain indexing solution providing developers and data analysts building on Celo and any other EVM-compatible chain with a seamless and efficient way to index and aggregate real-time and historical blockchain data. The indexed data is easily accessible through custom GraphQL queries, giving developers and analysts the flexibility and power to retrieve specific information.

Designed to optimize the user experience, Envio offers automatic code generation, flexible language support, quickstart templates, and a reliable cost-effective hosted service.

Envio HyperSync

Envio supports HyperSync on Celo Mainnet.⚡

Envio natively supports indexing data on EVM-compatible blockchains, like Celo, by using an RPC URL. Though this might be suitable for smaller applications, RPC URLs can become a bottleneck for more data-heavy use cases, sometimes taking hours or even days, to sync data from the blockchain. This can lead to increased downtime for applications that need to reindex their data and also provides an unfavourable developer experience.

Envio has also added HyperSync to Celo Mainnet to alleviate these challenges. HyperSync is an accelerated real-time data query layer for the Celo blockchain, providing APIs that bypass JSON-RPC for up to 1000x faster syncing of historical data. What would usually take hours to sync 100,000 events can now be done in the order of less than a minute. HyperSync is used by default in Envio’s indexing framework, with the use of RPC being optional.

Using HyperSync, application developers and data analysts do not need to worry about RPC URLs, rate limits, or managing their own infrastructure.

HyperSync is also available as a standalone API for data analytic use cases. Data analysts can interact with the HyperSync API using JavaScript, Python, or Rust clients and extract data in JSON, Arrow, or Parquet formats. For more information, visit the HyperSync documentation here.

Prerequisites

Before we start indexing, please make sure you have the following prerequisites 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 to index the largest Celo Dollar (c.USD) token transfers on Celo.

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

2. Name your indexer anything you’d like (e.g. “celo-dollar-indexer”).

3. Choose your preferred language and select Evm.

Note: Indexers on Envio can be written in JavaScript, TypeScript, or ReScript.

4. Select Contract Import, navigate to Block Explorer and select Celo.

5. Head over to CeloScan, copy and paste an existing contract address, and choose the events you’d like to index. In this example, we’ll be indexing the Transfer event.

USD Token Contract address: 0x765DE816845861e75A25fCA122bb6898B8B1282a

To select an event navigate using the arrow keys (↑ ↓) and click the space bar once you have made your choice.

Note: Multiple events can be selected and indexed at the same time.

6. Finally, review the configuration and select I’m finished to start generating the indexer or continue adding more addresses for the same contract on the same network, addresses for the same contract on a different network or a different contract.

For more information on the no-code contract import feature, visit the documentation here.

Starting the Indexer

Before starting your indexer, run the command below to ensure that no conflicting indexers are running.

Stopping the indexer

envio stop

Note: Ignore if you’re a first-time user.

Start the indexer

Now, let’s run our indexer locally by running the command below.

envio dev

Exploring the Indexed Data

Well done degens, now let’s explore the indexed data!

  1. Head over to Hasura, type in the admin-secret password (“testing”), and click “API” in the above column to access the GraphQL endpoint to query real-time data.

2. Navigate to “Data” in the above column to monitor the indexing progress on Celo through the events sync state table to see which block number you are on.

3. Now 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, StableTokenV2_2 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 StableTokenV2_2 Transfer 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.

Run queries to explore specific events, such as the largest c.USD transfers.

Conclusion

Congratulations! You’ve successfully generated an indexer and indexed every c.USD token transfer event in under 5 minutes on the Celo Network.

Visit our YouTube channel for more video tutorials that showcase Envio’s blockchain indexing features and capabilities.

Key Features

Envio supports the Celo Network and any EVM-compatible blockchain network with:

  • Flexible language support: Configure your event handling in familiar and widely supported languages, such as JavaScript, TypeScript, or ReScript.
  • HyperSync: To ensure blazing-fast retrieval of historical on-chain data and a seamless developer experience, Envio’s HyperSync endpoint allows up to 1000x faster indexing than standard RPC (use of RPC is optional).
  • No-code Quickstart: Autogenerate the key boilerplate for an entire Indexer project off single or multiple smart contracts. Deploy within minutes.
  • Multi-chain Support: Aggregate data across multiple networks into a single database. Query all your data with a unified GraphQL API.
  • ​​Join on-chain and off-chain data Asynchronous handler mode: Fetch data from off-chain storage such as IPFS, or contract state (e.g. smart contract view functions) to create a rich API.
  • Factory Contracts: Automatically process events emitted by all child contracts that are created by the specified factory.
  • Hosted Service: A managed service platform for building, hosting and querying Envio’s Indexers with guaranteed uptime and performance service level agreements.

Envio Indexer Examples

Click here for other Envio Indexer examples.

Click here for Envio HyperSync examples.

Getting Help

Data indexing can be a rollercoaster, especially for more complex use cases. Our engineers are available to help you with your data availability needs.

Join our growing community of elite builders, and find peace of mind with Envio.

Website | X | Discord | Hey | Medium | YouTube | Reddit

Email: hello@envio.dev

About Envio

Envio is a modern, dev-friendly, speed-optimized blockchain indexing solution that addresses the limitations of traditional blockchain indexing approaches and gives developers peace of mind. Blockchain developers and data analysts can harness the power of Envio to overcome the challenges posed by latency, reliability, infrastructure management, and costs across various sources.

If you’re a blockchain developer looking to enhance your development process and unlock the true potential of Web3 infrastructure, look no further.

--

--

Envio

The Modular Data Stack. The fastest, most flexible way to get on-chain data. Any EVM L1, L2, L3 & Fuel. ⚡