Skip to content

Latest commit

 

History

History
1305 lines (925 loc) · 55.9 KB

web3.eth.rst

File metadata and controls

1305 lines (925 loc) · 55.9 KB

web3.eth API

Warning

Whoa there, Binance Smart Chain user! web3.py is an Ethereum-specific library, which now defaults to "type 2" transactions as of the London network upgrade. BSC apparently does not support these newer transaction types.

From issues opened, it seems BSC transactions must include gasPrice, but not type, maxFeePerGas, or maxPriorityFeePerGas. If you have trouble beyond that, please find an appropriate BSC forum to raise your question.

The web3.eth object exposes the following properties and methods to interact with the RPC APIs under the eth_ namespace.

By default, when a property or method returns a mapping of keys to values, it will return an AttributeDict which acts like a dict but you can access the keys as attributes and cannot modify its fields. For example, you can find the latest block number in these two ways:

>>> block = web3.eth.get_block('latest')
AttributeDict({
  'hash': '0xe8ad537a261e6fff80d551d8d087ee0f2202da9b09b64d172a5f45e818eb472a',
  'number': 4022281,
  # ... etc ...
})

>>> block['number']
4022281
>>> block.number
4022281

>>> block.number = 4022282
Traceback # ... etc ...
TypeError: This data is immutable -- create a copy instead of modifying

This feature is available via the attrdict_middleware which is a default middleware.

Note

Accessing an AttributeDict property via attribute will break type hinting. If typing is crucial for your application, accessing via key / value, as well as removing the attrdict_middleware altogether, may be desired.

Properties

The following properties are available on the web3.eth namespace.

Note

This property gets called frequently in validation middleware, but chain_id is added to the simple_cache_middleware by default. Add the simple_cache_middleware<web3.middleware.construct_simple_cache_middleware> to the middleware_onion to increase performance:

>>> from web3.middleware import simple_cache_middleware
>>> w3.middleware_onion.add(simple_cache_middleware)

Methods

The following methods are available on the web3.eth namespace.

Filters

The following methods are available on the web3.eth object for interacting with the filtering API.

Contracts