Indexing Greeter contract using Envio
This tutorial will take you through a step-by-step guide to indexing a live Greeter smart contract using Envio.
Background
Greeter contract
The Greeter contract is a very simple smart contract that allows a user to write a greeting message on the blockchain.
The Greeter contract is deployed on both the Polygon and the Linea blockchain. Following this tutorial will index events from both chains.
Envio
Envio is a framework for developing a backend to index and aggregate blockchain data into a graphQL query-able database.
Prerequisites
Environment tooling
- Node.js we recommend using something like fnm or nvm to install Node
- pnpm
- Docker Desktop
Install Envio
npm i -g envio
Step by step instructions
Initialize the project
Initialize the project using the Greeter template.
Run
envio init
Choose the directory where you would like to set up your project (default is the current directory)
? Set the directory: (.) .
Then choose a language of your choice for the event handlers.
? Which language would you like to use?
> JavaScript
TypeScript
ReScript
[↑↓ to move, enter to select, type to filter]
Select to start from a template
? Choose an initialization option
> Template
Contract Import
Subgraph Migration (Experimental)
[↑↓ to move, enter to select, type to filter]
Choose Greeter
when prompted to choose a template.
? Which template would you like to use?
> Greeter
Erc20
[↑↓ to move, enter to select, type to filter]
Start the indexer
Dev note: 📢 make sure you have docker open
The following commands will start the docker and create databases for indexed data, make sure to re-run dev
if you make changes to the files
Run
envio dev
The indexer will then start indexing the contract's specified in the config.yaml
file from the start_block
specified for each network.
Write to the contracts on Polygon and Linea using the block explorers
Once the indexer is running, you can call functions on the Greeter contract that is deployed on Polygon and Linea, using the respective network's blockchain explorer.
For Polygon, navigate to the contract on Polygonscan and the call setGreeting
function.
For Linea, navigate to the contract on Lineascan and call the setGreeting
function.
In the case of a multi-chain indexing example, you can call the setGreeting
function on both contracts.
View the indexed results
You can view the indexed results on a local Hasura server.
open http://localhost:8080
The Hasura admin-secret / password is testing
and the tables can be viewed in the data
tab or queried from the playground
Deploy the indexer onto the hosted service
Once you have verified that the indexer is working for the Greeter contracts, then you are ready to deploy the indexer onto our hosted service.
Deploying an indexer onto the hosted service allows you to extract information via graphQL queries into your front-end or some back-end application.
Navigate to the hosted service to start deploying your indexer and refer to this documentation for more information on deploying your indexer.
What next?
Once you have successfully finished the Greeter tutorial, you are ready to become a blockchain indexing wizard!
Jump into the Importing Contracts page to generate a basic indexing template for a contract that is deployed on the blockchain!
You can also start to modify the handlers to your own custom indexing logic.