Skip to content

fix: filter contract events by address before decoding#6224

Merged
rajk93 merged 1 commit intomasterfrom
rk/decode-event
Nov 19, 2025
Merged

fix: filter contract events by address before decoding#6224
rajk93 merged 1 commit intomasterfrom
rk/decode-event

Conversation

@rajk93
Copy link
Contributor

@rajk93 rajk93 commented Nov 12, 2025

fixes #5583

Description

When a contract calls another contract, both emit ContractEmitted events. The current implementation attempts to decode all events using only the calling contract's ABI, resulting in errors like:

CONTRACT: Unable to decode contract event: Unable to find event with index 1
CONTRACT: Unable to decode contract event: Unable to determine event

This occurs because the decoder tries to interpret events from Contract B using Contract A's ABI, as mentioned in #5583 (comment).

This PR filters events by contract address before decoding. Each contract instance now only decodes events where event.data[0] (the emitting contract address) matches this.address. Events from other contracts are skipped and
logged at the debug level for visibility.

Impact on Different Ink Contract Metadata Versions

ink! v4 (metadata v4): Uses index-based event lookup. This fix is critical as it prevents Unable to find event with index X errors when cross-contract calls occur.

ink! v5+ (metadata v5/v6): Uses signature topics for event matching, which provides better event discrimination. However, this fix is still beneficial because it eliminates error logs when signature topics don't match between contracts

@rajk93 rajk93 marked this pull request as ready for review November 12, 2025 12:54
@rajk93 rajk93 merged commit 4737d65 into master Nov 19, 2025
4 checks passed
@rajk93 rajk93 deleted the rk/decode-event branch November 19, 2025 11:53
@polkadot-js-bot
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Nov 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unable to decode contract events

4 participants