Ethers.EventFilter (Ethers v0.7.0)

Copy Markdown View Source

Event Filter struct and helper functions to work with the event filters

Summary

Types

t()

Holds event filter topics, the event selector and the default address.

Functions

Combines multiple event filters into a single Ethers.CombinedEventFilter matching any of the given events (OR semantics) in one eth_getLogs request.

Types

t()

@type t() :: %Ethers.EventFilter{
  default_address: nil | Ethers.Types.t_address(),
  selector: ABI.FunctionSelector.t(),
  topics: [binary()]
}

Holds event filter topics, the event selector and the default address.

Can be passed in to Ethers.get_logs/2 filter and fetch the logs.

Functions

combine(event_filters)

@spec combine([t() | module()] | module()) :: Ethers.CombinedEventFilter.t()

Combines multiple event filters into a single Ethers.CombinedEventFilter matching any of the given events (OR semantics) in one eth_getLogs request.

The combined filter can be used anywhere a regular event filter is accepted (e.g. Ethers.get_logs/2 and Ethers.batch/2). Filtering happens server side using an OR-ed list of topic_0 values and each fetched log is decoded using its matching event selector.

Accepts event filters as well as EventFilters modules of contracts, which translate to all events of that contract. (e.g. Ethers.Contracts.ERC20.EventFilters)

Rules

Raises ArgumentError if:

  • The list of filters is empty.
  • Any filter has indexed-argument values. Only wildcard filters (all indexed arguments set to nil) can be combined, since eth_getLogs topics are positional and OR-ing them across events would match unintended logs.
  • Filters have conflicting default addresses. eth_getLogs accepts a single address, so all combined filters must belong to the same contract.

Examples

filter =
  Ethers.EventFilter.combine([
    Ethers.Contracts.ERC20.EventFilters.transfer(nil, nil),
    Ethers.Contracts.ERC20.EventFilters.approval(nil, nil)
  ])

Ethers.get_logs(filter, address: "0x...")
#=> {:ok, [%Ethers.Event{...}, ...]}

# All events of a contract
Ethers.EventFilter.combine([Ethers.Contracts.ERC20.EventFilters])