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
- Immutable Data: Returned objects (
AttributeDict) prevent field modifications but allow attribute access. - Type Hinting Note: Attribute access may break type hints; use dictionary access or disable
AttributeDictMiddlewareif typing is critical.
# 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
| Property | Description |
|---|---|
default_account | Ethereum address used as default from in transactions. |
default_block | Default block identifier (default: 'latest'). |
syncing | Returns sync status or False if not syncing. |
max_priority_fee | Suggested max priority fee (Wei) for dynamic fee transactions. |
gas_price | Current gas price (Wei). |
accounts | List of known accounts. |
block_number | Latest block number (alias for get_block_number()). |
chain_id | Chain ID (EIP-155); None if unavailable. |
Methods
Blockchain Data
get_balance(account, block_identifier): Returns account balance at specified block.get_block(block_identifier, full_transactions=False): Retrieves block data.get_transaction(transaction_hash): Returns transaction details.get_transaction_receipt(transaction_hash): Retrieves transaction receipt.
Transactions
send_transaction(transaction): Signs and sends a transaction.estimate_gas(transaction): Estimates gas consumption for a transaction.
# Example: Sending a transaction
tx_hash = web3.eth.send_transaction({
'to': '0x...',
'from': web3.eth.accounts[0],
'value': 12345
})Filters
filter(filter_params): Creates event filters (logs/blocks/pending transactions).get_filter_changes(filter_id): Returns new entries since last poll.uninstall_filter(filter_id): Removes a filter.
Contracts
contract(address=None, abi=None): Instantiates or returns a contract class.# Example: Deploying/interacting with a contract Contract = web3.eth.contract(abi=...) deployed_contract = Contract(address='0x...')
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