Factory contracts dynamically create child contracts, requiring special handling for indexing. This guide explains how to effectively track and index both factory and child contracts using Blockflow.
To index factory contracts effectively, you’ll need to:
Track the child contract creation events from the factory contract.
Use Blockflow’s sdk library to initialise and index the child contract.
Define event handlers to process and store event data.
Define schemas to specify the structure of the indexed data.
Prerequisites
Blockflow CLI
Docker
Key Concepts
Factory contracts have two key characteristics when indexing:
The factory contract has a fixed address
Child contracts have dynamic addresses that are created at runtime
Step-by-Step Implementation
1. Configure Resources in YAML
Define both the factory contract and its child contract template in your studio.yaml:
After completing the code, run the blockflow test command to fill up data. To access the local GraphQL API, add an API resource in the Resources section and set the YAML type to api.
This guide covers configuring a factory contract to track child creation events, initialising child contracts, and storing event data in a managed database. By following this setup, you can index factory-child relationships for UniswapV2 and view the data through a GraphQL API.
Read more at: https://github.com/blockflowlabs/cli-examples/tree/v2-examples/v2/uniswap