degenbot.provider.sync¶

Synchronous Alloy provider: the mixin trees and AlloyProvider.

The async twin lives in degenbot.provider.async_provider. The two trees are deliberately parallel: 20 of the 22 methods they share are logic-identical modulo await, and nearly all of those are single-line pass-throughs to the wrapped Rust pyclass – the sync/await duality IS the code. The multi-line logic both trees need (block-tag resolution, block-timestamp extraction) lives once in degenbot.provider.block_helpers. get_logs genuinely differs: the sync surface accepts a LogFilter or individual keyword arguments with range validation; the async surface takes keyword arguments only.

Module Contents¶

class degenbot.provider.sync.LogFilter¶

Filter criteria for log fetching.

Parameters:
  • from_block – Starting block number (inclusive)

  • to_block – Ending block number (inclusive)

  • addresses – Contract addresses to filter (optional)

  • topics – Event topic signatures, nested by position (optional)

Example

>>> filter = LogFilter(
...     from_block=18_000_000,
...     to_block=18_010_000,
...     addresses=["0xContractAddress..."],
...     topics=[["0xTransfer..."]],  # Match first topic
... )
from_block: degenbot.types.aliases.BlockNumber¶
to_block: degenbot.types.aliases.BlockNumber¶
addresses: list[str] = []¶
topics: list[list[str]] = []¶
class degenbot.provider.sync.AlloyProvider(rpc_url: str, max_retries: int = 10, max_blocks_per_request: int = 5000, chain_id: int | None = None)¶

Bases: _AlloyEndpointMixin, _AlloyQueryMixin, _AlloyIntrospectionMixin

High-performance Ethereum RPC provider using Alloy.

Backs log fetching and basic RPC calls with a Rust HTTP client using connection pooling for optimal performance. The public surface is assembled from the query mixins; this class owns construction and teardown of the wrapped Rust provider.

Parameters:
  • rpc_url – HTTP/HTTPS endpoint URL

  • max_retries – Maximum retry attempts (default: 10)

  • max_blocks_per_request – Maximum logs per request (default: 5000)

  • chain_id – Chain to bind the endpoint to. The Rust core reads eth_chainId once at construction and raises ValueError when the endpoint serves another chain; None constructs the provider with no binding.

Example

>>> provider = AlloyProvider("https://eth-mainnet.example.com")
>>>
>>> # Properties
>>> chain_id = provider.chain_id
>>> block_number = provider.block_number
>>>
>>> # Methods
>>> block = provider.get_block(18_000_000)
>>> logs = provider.get_logs(from_block=18_000_000, to_block=18_010_000)
>>> code = provider.get_code("0x...")
>>> result = provider.call("0x...", calldata)