TopicFilter

public final class TopicFilter : Sendable

Topic-based filter for querying contract events.

TopicFilter allows filtering events by their topic values. Topics are indexed parameters emitted with contract events, typically including the event name and key parameters.

Topic matching:

  • Use exact values to match specific topics (e.g., “transfer”)
  • Use “*” as a wildcard to match any value at that position

Example:

// Match transfer events to a specific address
let topicFilter = TopicFilter(segmentMatchers: [
    "transfer",    // Topic 0: event name
    "*",          // Topic 1: any sender
    "GADDR..."    // Topic 2: specific recipient
])

let eventFilter = EventFilter(
    type: "contract",
    topics: [topicFilter]
)

See also:

  • [EventFilter] for complete event filtering
  • [SorobanServer.getEvents] for querying events
  • Stellar developer docs
  • Topic segment matching patterns using exact values or wildcards for event filtering.

    Declaration

    Swift

    public let segmentMatchers: [String]
  • Creates a topic filter with segment matchers for filtering contract events by topic values.

    Declaration

    Swift

    public init(segmentMatchers: [String])