gleeth/events
Query and decode contract events in a single call.
Combines methods.get_logs with ABI event decoding so you don’t have
to manually match topic hashes and decode parameters.
Examples
let assert Ok(abi) = json.parse_abi(erc20_abi_json)
let assert Ok(decoded) = events.get_events(
provider,
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
abi,
"0x100000",
"latest",
)
// decoded: List(EventResult) - each with event name and typed params
Types
Result of decoding a single event log.
pub type EventResult {
Decoded(event: events.DecodedLog, log: types.Log)
Unknown(log: types.Log)
}
Constructors
-
Decoded(event: events.DecodedLog, log: types.Log)Successfully decoded event with name and typed parameters.
-
Unknown(log: types.Log)Log could not be matched to any event in the ABI.
Values
pub fn compute_event_topic(
abi: List(json.AbiEntry),
event_name: String,
) -> String
pub fn decode_logs(
logs: List(types.Log),
abi: List(json.AbiEntry),
) -> List(EventResult)
Decode a list of raw logs against an ABI. Useful when you already have logs from another source (e.g. a transaction receipt).
Examples
let results = events.decode_logs(receipt.logs, abi)
pub fn get_events(
provider: provider.Provider,
address: String,
abi: List(json.AbiEntry),
from_block: String,
to_block: String,
) -> Result(List(EventResult), types.GleethError)
Query logs for a contract and decode them against the provided ABI.
Logs that match an event in the ABI are decoded; unmatched logs are
returned as Unknown so no data is lost.
Examples
let assert Ok(events) = events.get_events(
provider, "0xA0b8...", abi, "0x100000", "latest",
)
pub fn get_events_by_name(
provider: provider.Provider,
address: String,
abi: List(json.AbiEntry),
event_name: String,
from_block: String,
to_block: String,
) -> Result(List(EventResult), types.GleethError)
Query logs for a specific event name. Filters by the event’s topic0 hash, so only matching logs are returned from the RPC.
Examples
let assert Ok(transfers) = events.get_events_by_name(
provider, "0xA0b8...", abi, "Transfer", "0x100000", "latest",
)