Skip to content

fix(encodeEventTopics): do not prepend signature topic for anonymous events#4613

Merged
jxom merged 2 commits into
wevm:mainfrom
Kropiunig:fix/encode-event-topics-anonymous
May 17, 2026
Merged

fix(encodeEventTopics): do not prepend signature topic for anonymous events#4613
jxom merged 2 commits into
wevm:mainfrom
Kropiunig:fix/encode-event-topics-anonymous

Conversation

@Kropiunig
Copy link
Copy Markdown
Contributor

What is this PR solving?

encodeEventTopics always prepended the event selector as the first topic, even for anonymous events. Anonymous events are not identified by a signature topic, so the encoded topics were incorrect and could not be used to filter logs.

This adds an anonymous check: for anonymous events the indexed-argument topics are returned as-is, without the leading signature topic. Non-anonymous events are unchanged.

Closes #4461

What's changed

  • src/utils/abi/encodeEventTopics.ts: skip prepending the event selector when abiItem.anonymous is true. The selector is now only computed for non-anonymous events.
  • EncodeEventTopicsReturnType widened from [Hex, ...(Hex | Hex[] | null)[]] to (Hex | Hex[] | null)[], since anonymous events can produce a signature-less (and possibly empty) topic list. This is a superset of the previous type; no internal callers rely on the tuple shape.

What alternatives were explored?

Keeping the strict tuple return type and only changing runtime behavior. This was rejected because the tuple type makes a valid (signature-less) anonymous-event result fail typechecking.

What should reviewers pay attention to?

  • Non-anonymous event encoding is byte-for-byte unchanged (signature still prepended, existing tests untouched).
  • The widened return type — decodeEventLog already models the signature-less case with | [], so this aligns the encode side.

Tests

Added src/utils/abi/encodeEventTopics.test.ts > https://github.com/wevm/viem/issues/4461 covering anonymous events with: no args, a leading indexed arg, all indexed args, and unnamed args.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 14, 2026

🦋 Changeset detected

Latest commit: 5082ead

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

@vercel
Copy link
Copy Markdown

vercel Bot commented May 14, 2026

@Kropiunig is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 14, 2026

Open in StackBlitz

npm i https://pkg.pr.new/viem@4613

commit: 25a8a95

…events

Make `EncodeEventTopicsReturnType` conditional on whether the resolved
event is anonymous. Non-anonymous events keep the strict
`[Hex, ...(Hex | Hex[] | null)[]]` tuple shape (preserving destructuring
ergonomics), while anonymous events return `(Hex | Hex[] | null)[]`.
@jxom jxom merged commit bd1d244 into wevm:main May 17, 2026
15 of 23 checks passed
@github-actions github-actions Bot mentioned this pull request May 17, 2026
@tmm tmm mentioned this pull request May 26, 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