Writing handlers
The handler functions act as a bridge between the raw on-chain data and the structured, queryable format required by the database.
By writing custom logic in these handlers, developers can tailor the indexing process to meet their specific requirements, ensuring that the indexed data is organized and formatted in a meaningful way for efficient querying and analysis.
Input Context
Each handler function receives an input object containing all the relevant on-chain information related to the event or function call that triggered the handler. The content and structure of this input object vary depending on the type of handler (event or function) and the specific blockchain data being indexed.
IEventContext
IFunctionContext
Database CRUD Operations in Handlers
Within the handler functions, you can perform various Create, Read, Update, and Delete (CRUD) operations on the indexed data stored in the database. The @blockflow-labs/sdk
library provides utility functions to facilitate these operations
Using BigNumber.js
Smart contract generally deals in large integers like uint256 which is not handled by javascript properly. Hence it is recommended to use BigNumber libraries like ethers.js and BigNumber.js. These libraries are particularly useful when working with uint256
values.
To use BigNumber.js in your subgraph project, you can import it into your handler files:
Once imported, you can create BigNumber instances and perform various operations on them:
BigNumber.js provides a wide range of methods for performing arithmetic operations, comparison, formatting, and more, allowing you to handle large integers accurately and efficiently. You can check out the library here.
Last updated