Web3.eth API — Web3.py 7.12.0 Documentation

·

The web3.eth object provides methods and properties to interact with Ethereum's RPC APIs under the eth_ namespace. By default, returned mappings are AttributeDict instances—immutable dictionaries allowing attribute-style key access.

Key Features

# Example: Accessing block data
block = web3.eth.get_block('latest')
block['number']    # Dictionary access
block.number       # Attribute access
block.number = 42  # Raises TypeError (immutable)

Properties

PropertyDescription
default_accountEthereum address used as default from in transactions.
default_blockDefault block identifier (default: 'latest').
syncingReturns sync status or False if not syncing.
max_priority_feeSuggested max priority fee (Wei) for dynamic fee transactions.
gas_priceCurrent gas price (Wei).
accountsList of known accounts.
block_numberLatest block number (alias for get_block_number()).
chain_idChain ID (EIP-155); None if unavailable.

Methods

Blockchain Data

Transactions

# Example: Sending a transaction
tx_hash = web3.eth.send_transaction({
    'to': '0x...',
    'from': web3.eth.accounts[0],
    'value': 12345
})

Filters

Contracts

FAQs

How do I access immutable data returned by web3.eth?

Use either dictionary-style (block['number']) or attribute access (block.number). Modifications raise a TypeError.

What’s the recommended way to handle gas fees post-London fork?

Use maxFeePerGas and maxPriorityFeePerGas in transactions instead of gasPrice for dynamic fee support.

👉 Explore dynamic fee transactions

How can I fetch historical event logs?

Create a log filter with web3.eth.filter({'fromBlock':..., 'toBlock':...}) and poll using get_filter_changes().

👉 Learn more about Ethereum event logs


### Key SEO Keywords
- Ethereum RPC API
- Web3.py documentation
- Smart contract interaction
- Blockchain transactions