EventFetcher¶
Event fetching and parsing utilities for the Arbitrum SDK.
This module provides classes for fetching and parsing blockchain events/logs in a structured way, similar to the TypeScript EventFetcher implementation.
- class arbitrum_py.utils.event_fetcher.FetchedEvent(*, event, topic, name, block_number, block_hash, transaction_hash, address, topics, data)[source]¶
Bases:
CaseDictA structured representation of an Ethereum event/log.
This class represents a parsed blockchain event, containing both the decoded data (event arguments) and the raw log information. It’s the Python equivalent of the TypeScript FetchedEvent<TEvent> type.
- Variables:
event (Dict[str, Any]) – The decoded event arguments
topic (Optional[str]) – The primary topic (event signature)
name (str) – The event name (e.g., “MessageDelivered”)
block_number (int) – Block number containing the event
block_hash (str) – Hash of the block containing the event
transaction_hash (str) – Hash of the transaction containing the event
address (str) – Contract address that emitted the event
topics (List[str]) – All topics from the log
data (Optional[str]) – Raw data from the log
- __init__(*, event, topic, name, block_number, block_hash, transaction_hash, address, topics, data)[source]¶
Initialize a FetchedEvent instance.
- Parameters:
event (
Dict[str,Any]) – The decoded event argumentstopic (
Optional[str]) – Primary topic (event signature) if anyname (
str) – Event name (e.g., “MessageDelivered”)block_number (
int) – Block number containing the eventblock_hash (
str) – Hash of the block containing the eventtransaction_hash (
str) – Hash of the transaction containing the eventaddress (
NewType()(ChecksumAddress,NewType()(HexAddress,NewType()(HexStr,str)))) – Contract address that emitted the eventtopics (
List[str]) – All topics from the logdata (
Optional[str]) – Raw data from the log
- class arbitrum_py.utils.event_fetcher.EventFetcher(provider)[source]¶
Bases:
objectA utility class for fetching and parsing blockchain events.
This class provides functionality to: 1. Query blockchain logs using various filters 2. Parse the logs into structured FetchedEvent objects 3. Handle different provider types (Web3, SignerOrProvider, ArbitrumProvider)
It’s the Python equivalent of the TypeScript EventFetcher class.
- __init__(provider)[source]¶
Initialize an EventFetcher instance.
- Parameters:
provider (
Union[Web3,SignerOrProvider,ArbitrumProvider]) – The provider to use for fetching logs. Can be: - A Web3 instance - A SignerOrProvider instance - An ArbitrumProvider instance- Raises:
ArbSdkError – If the provider is invalid or missing
- get_events(contract_factory, event_name, argument_filters=None, filter=None, is_classic=False)[source]¶
Fetch and parse blockchain events.
This method: 1. Sets up the contract interface 2. Creates an event filter 3. Fetches matching logs 4. Parses them into FetchedEvent objects
- Parameters:
contract_factory (
Union[str,Contract]) – Either a contract name string or Contract instanceevent_name (
str) – Name of the event to fetch (e.g., ‘MessageDelivered’)argument_filters (
Optional[Dict[str,Any]]) – Filters for specific event argument valuesfilter (
Optional[FilterParams]) – Block range and address filters containing: - fromBlock: Starting block number - toBlock: Ending block number - address: Contract address (optional)is_classic (
bool) – Whether to use classic or nitro contract version
- Returns:
The fetched and parsed events
- Return type:
List[FetchedEvent]
- Raises:
ArbSdkError – If contract or event cannot be found/accessed
Example
>>> fetcher = EventFetcher(web3) >>> events = fetcher.get_events( ... contract_factory='Bridge', ... event_name='MessageDelivered', ... filter={'fromBlock': 1000000, 'toBlock': 'latest'} ... )