starknet.js: Bug parsing events when nested events involved

Location: https://github.com/starknet-io/starknet.js/blob/66a5c0341eccfef0dcdf1312c15627b7d4f6b675/src/utils/events/index.ts#L52C21-L52C28

Encounter issue with parsing events emitted by components:

Sample of code (just take any events that emitted in nested components):

    const eventsC = provider.getEvents(....)
    const abiEvents = STARKNETJS.events.getAbiEvents(abi);
    const abiStructs =  STARKNETJS.CallData.getAbiStruct(abi);
    const abiEnums = STARKNETJS.CallData.getAbiEnum(abi);
    let parsedEvents = STARKNETJS.events.parseEvents(eventsC.events, abiEvents, abiStructs, abiEnums)
    console.log(parsedEvents)

produces 0 parsed events

Reason: AbiEvents not handle correctly case for nested events when they defined by extra key that associated with component. In my particular case second key was the correct one to do lookup to abiEvents Potential solution:

let abiEvent: EventAbi | undefined;

// Loop through all keys and find the first matching event
for (const key of recEvent.keys) {
    abiEvent = abiEvents[key];
    if (abiEvent) {
        break; // Exit the loop once a match is found
    }
}

iterate over all keys/or first N instead of just first one. I presume there should be no collisions

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 26

Most upvoted comments

Found some [#flat] in OpenZeppelin contracts. I have found a corresponding event. So, I finalize and clean my code. then, I will propose quickly a PR.

Hello, I coded something that is recursive and can handle several levels of components (even if it’s maybe not possible today). Could you try with this line in your package.json? :

"starknet": "philippeR26/starknet.js#c9fab45b78222154247d8078bb60af2dd30a9611",

Now, the result contains the full name of the event (was just the last word), to differentiate the events with the same name. Waiting your response.

yeap works

For the test suite of Starknet.js, could you provide me a link in Sepolia for an example these events :

  • kurosawa_akira::DepositComponent::deposit_component::Deposit
  • kurosawa_akira::RouterComponent::router_component::Deposit

OK, I have now a good understanding of this problem. I will use a nested findIndex / includes to find the right key.

Seems to be the hash of BalancerEvent