fetch_all_events

Documentation for eth_defi.event.fetch_all_events function.

fetch_all_events(web3, event, address=None, argument_filters=None, from_block=1, to_block=None)[source]

Get events using eth_getLogs API.

This is a stateless method, as oppose to JSON-RPC filter objects. It can be safely called against nodes which do not provide eth_newFilter API, like Infura.

We are not doing any throttling or API error recovery: If you ask for too many events once this function and your Ethereum node are likely to blow up.

Example how to get all ERC-20 transfers to a target address:

IERC20 = get_contract(web3, "IERC20.json")
Transfer = IERC20.events.Transfer
all_transfers_to_user = list(fetch_all_events(web3, Transfer, argument_filters={"to": owner}))
Parameters
  • web3 (web3.main.Web3) – Web3 instance

  • event (Type[web3.contract.ContractEvent]) – Event class grabbed from a Contract proxy class, like IERC20.events.Transfer.

  • address (Optional[HexAddress]) – The smart contract address of the event emitter. Set to none to capture events from all the smart contracts.

  • argument_filters (Optional[dict]) – Filters based on the event structure, e.g. to field IERC20.events.Transfer

  • from_block (Optional[BlockNumber]) – Limit block range. Set to 1 to get all the events, ever.

  • to_block (Optional[BlockNumber]) – Limit block range

Return type

Iterable[web3.datastructures.AttributeDict]