Envio is a reliable real-time indexing solution that makes it easy to ingest events from EVM-compatible chains and process that data into to custom APIs. These APIs are perfect for unlocking slick user experiences in blockchain application frontends.
The Aim of Envio is to optimize the developer experience of using an indexer, whilst providing fast, secure, and reliable indexing service.
This repo uses clap
CLI library.
Help file for CLI commands can be found here
Install prerequisite tools:
- Node.js (install v18) https://nodejs.org/en (Recommended to use a node manager like fnm or nvm)
- pnpm
npm install --global pnpm
- Cargo https://doc.rust-lang.org/cargo/getting-started/installation.html
Run
curl https://sh.rustup.rs -sSf | sh
- Docker Desktop https://www.docker.com/products/docker-desktop/
Install Envio:
cargo install --path codegenerator
Command to see available CLI commands
envio --help
cd
into a folder of your choice and run
envio init
Then choose a template out of the possible options
? Which template would you like to use?
> "Gravatar"
[↑↓ to move, enter to select, type to filter]
Then choose a language from Javascript, Typescript, or Rescript to write the event handlers file.
? Which language would you like to use?
> "Javascript"
"Typescript"
"Rescript"
[↑↓ to move, enter to select, type to filter
This will generate the config, schema, and event handlers files according to the template and language chosen.
Here is an example of how to configure the files for indexing.
Once you have configured the above files and deployed the contracts, the following can be used to generate all the code that is required for indexing your project:
envio codegen
Once all the configuration files and auto-generated files are in place, you are ready to run the indexer for your project:
pnpm start
To view the data in the database, run
./generated/register_tables_with_hasura.sh
and open http://localhost:8080/console.
Admin-secret for local Hasura is testing
Alternatively, you can open the file index.html
for a cleaner experience (no Hasura stuff). Unfortunately, Hasura is currently not configured to make the data public.
Below are steps to be followed when testing the indexer locally using Hardhat and Docker.
NB: All the files must be configured as per the guidelines above.
-
Removing stale data
docker-compose down -v
-
Restarting docker
docker-compose up -d
-
Deploying contract
cd contracts rm -r deployments pnpm hardhat deploy
Note that this will delete the previous deployment of the smart contract and re-deploy it to prevent
node synced status
errors.More information on how to deploy contracts using Hardhat can be found here.
-
Generating code Once you are in your project directory, run:
envio codegen
-
Running the indexer
pnpm start
-
Running some tasks
pnpm hardhat task:1 --parameter-1 value-1
More information on how to create and run tasks using Hardhat can be found here.
-
Checking the results on local Hasura
./generated/register_tables_with_hasura.sh
and open http://localhost:8080/console.
If you have updated your smart contract after the initial codegen, then you will have to recreate the ABI for your smart contract.
Run
cd contracts
pnpm hardhat export-abi
Ensure that the directory for ABI in config.yaml is pointing to the correct folder where ABIs have been freshly generated.