Project Structure
Last updated
Last updated
This page provides an overview of the project structure of a blockflow project. It covers top-level files and folders, configuration file, and schema file.
Click the file and folder names to learn more about each convention.
After completing the project initiation step, the CLI generates a folder structure with all the necessary boilerplate code set up. Let's explore this folder structure in detail:
The studio.yaml
file is a crucial component of your project. It serves as the main configuration file, defining the structure and behaviour of your indexer.
This YAML file specifies the details, including:
The blockchain network it will connect to (e.g., Ethereum, Polygon, etc.)
The smart contracts it will index and their addresses
The events and data entities to be indexed from those contracts
The mapping functions that transform the raw blockchain data into the desired format
The studio.schema.ts
file is a TypeScript file responsible for defining the databases configuration and their schema. It specifies the entities and their relationships within the indexed blockchain data.
In this file, you define the structure of the data entities that will be stored. And also the configuration of database. These entities represent the various types of data you want to index from the blockchain, such as smart contracts, events, and any relevant data associated with them.
Remember no comments are allowed in studio.schema.ts
Once done with defining the schema. You need to run below code to get started.
A types
folder will generated inside src folder containing generated.ts
file and graphql.ts
file.
The mapping functions defined in the handlers
directory are automatically triggered and executed whenever a specific event or function is emitted or called on the blockchain. Each mapping function is associated with a particular event or function from the smart contracts being indexed defined in studio.yaml
file.
To generate boilerplate code for these handler use below command.
Here, an example of handler's boilerplate code.
We will dive deeper into this code in handlers section.
The abis
folder is used to store the Application Binary Interface (ABI) files for the smart contracts being indexed.
The root directory also contains a docker-compose.yml
file, which defines the services required for running a local testing environment. This file includes configurations for MongoDB, PostgreSQL, and Adminer.
Note: It is recommended to leave this file unchanged to ensure your environment runs smoothly without errors.
A .env.example
file is generated in the root directory as a sample configuration file. This file outlines the environment variables needed for your project. Before you start building or testing, rename it to .env
.
Make sure to fill in the required credentials, especially before deploying your project. For local testing, you can leave the default values, but if you need to connect to remote databases, feel free to update the database configuration variables accordingly.