Skip to content

fix(abi): handle anonymous events in encodeEventTopics#4463

Closed
Zelys-DFKH wants to merge 2 commits intowevm:mainfrom
DFKHelper:fix/encode-event-topics-anonymous
Closed

fix(abi): handle anonymous events in encodeEventTopics#4463
Zelys-DFKH wants to merge 2 commits intowevm:mainfrom
DFKHelper:fix/encode-event-topics-anonymous

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

Summary

Fixes #4461

Root cause

encodeEventTopics in src/utils/abi/encodeEventTopics.ts computes the event signature and prepends it as topic[0] unconditionally. Anonymous events do not include the signature as a topic — the EVM skips it entirely, giving anonymous events four indexed slots instead of three. Because abiItem.anonymous was never checked, encodeEventTopics was producing incorrect topics for any anonymous event.

Fix

Move the signature computation inside a guard and only prepend it for non-anonymous events:

```ts
if (abiItem.anonymous) return topics

const definition = formatAbiItem(abiItem)
const signature = toEventSelector(definition as EventDefinition)
return [signature, ...topics]
```

The return type is loosened from [Hex, ...(Hex | Hex[] | null)[]] to (Hex | Hex[] | null)[] since anonymous events with no args return an empty array.

Tests

Added three unit tests covering anonymous events: no args (returns []), partial args, and all args.

Notes

  • Non-anonymous event behaviour is unchanged.
  • The signature computation is skipped entirely for anonymous events, not just excluded from the output.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 5, 2026

@Zelys-DFKH is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 5, 2026

🦋 Changeset detected

Latest commit: 19bd5f6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jxom jxom closed this Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

encodeEventTopics() (and watchLogs()) do not handle anonymous events

2 participants