Pre-requisites: NodeJS, Git, Docker, Squid CLI, any of the EVM templates.
1. Model the target schema and generate entity classes
Create or editschema.graphql to define the target entities and relations. Consult the schema reference.
Update the entity classes, start a fresh database and regenerate migrations:
2. Generate Typescript ABI modules
Useevm-typegen to generate the facade classes, for example like this:
3. Configuration
See the EVM Portal stream reference for more details.4. Iterate over the batch items and group events
The following code snippet illustrates a typical data transformation in a batch. The strategy is to- Augment the raw blocks with
augmentBlock()to get item IDs and navigation helpers - Iterate over the blocks and their
logs - Decode each log using a suitable facade class
- Enrich and transform the data
- Upsert arrays of entities in batches using
ctx.store.save()
run() call then looks as follows:
NewGravatar and UpdatedGravatar with a single helper function that uses the generated events facade module. Decoder output types follow the ABI: the uint256 gravatar id comes out as a bigint (which we then format as a hex string to use as the entity ID) and the owner address as a hex string:
5. Run the processor and store the transformed data into the target database
Build the code, then run the processor:http://localhost:4350/graphql.