Skip to main content

Overview

Event.encodeTopics builds the topics array for an event filter. It includes topic0 (the event selector) for non-anonymous events and encodes indexed parameters as topics.

Quick Start

Wildcards and Partial Filters

Set an indexed value to null (or omit it) to leave that topic unconstrained:

Use in Log Filters

encodeTopics returns byte arrays. Convert to hex strings when passing to JSON-RPC:

Dynamic Indexed Parameters

Dynamic types (string, bytes, dynamic arrays, tuples with dynamic parts) are hashed with keccak256 before being placed in a topic. You cannot recover the original value from the topic alone.

Anonymous Events

Anonymous events omit topic0. encodeTopics will return only the indexed parameter topics.

See Also