The Graph.

Post

Share your knowledge.

TheGraph Mod QST.
Mar 30, 2024
Expert Q&A

How to index events from a contract via multicall?

I am currently facing an issue where I am unable to index events from a contract that is being muticalled from another contract. It seems that the events are not being found, possibly because they are emitted during the multicall. I would appreciate any suggestions or best practices on how to overcome this situation and successfully index the events. Thank you in advance for your assistance.

  • The Graph
  • Query
  • Indexers
  • Subgraph
0
1
Share
Comments
.

Answers

1
TheGraph Mod ANS.
Mar 30 2024, 00:36

You need to ensure that the subgraph's ABI has all the events coming from both smart contracts and the right contract is used as the data source for the handlers. Depending on whether the multicall is doing a regular call or a delegatecall, the contract emitting the event will be the callee or the multicall contract, respectively.

To make long story short, follow these steps:

  1. Identify the smart contracts involved: Determine the addresses or names of the smart contracts whose events you want to include in the subgraph's ABI.

  2. Retrieve the event definitions: Access the source code or documentation of each smart contract to find the event definitions. These definitions specify the structure and parameters of each event.

  3. Create a new subgraph: If you haven't already, create a new subgraph using a subgraph development framework like Graph Protocol. This framework allows you to define the entities, attributes, and event handlers for your subgraph.

  4. Define the entities: Identify the entities that your subgraph will track. These entities represent the data you want to index and query. Define the attributes for each entity, specifying the data you want to store.

  5. Add event handlers: In your subgraph's schema file, define event handlers for each event you want to include. These event handlers specify how the subgraph should process and index the events.

  6. Include event definitions: In the event handlers, include the event definitions from both smart contracts. This ensures that the subgraph recognizes and processes events from both sources.

  7. Build and deploy the subgraph: Use the subgraph development framework to build and deploy your subgraph. This process compiles your subgraph's code and deploys it to a hosting service.

  8. Test and verify: Once deployed, test your subgraph by querying for data and verifying that the events from both smart contracts are being indexed correctly.

By following these steps, you can ensure that the subgraph's ABI includes all the events coming from both smart contracts. This allows you to effectively track and query the data generated by these contracts.

0
Official Answer
Comments
.

Do you know the answer?

Please log in and share it.

The Graph is a decentralized protocol for indexing and querying blockchain data. The Graph makes it possible to query data that is difficult to query directly.

259Posts258Answers
Sui.X.Peera.

Earn Your Share of 1000 Sui

Gain Reputation Points & Get Rewards for Helping the Sui Community Grow.