Async Gas Price Strategy
- Dominant language
- Python
- Stars
- 5.5k
- Forks
- 1.7k
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 2
Description
### What happened?
I'm using an async node and set the gas price strategy to the default `fast_gas_price_strategy`. This yields a `TypeError: 'coroutine' object is not subscriptable`.
### Code that produced the error
```python
node_async.eth.set_gas_price_strategy(web3.gas_strategies.time_based.fast_gas_price_strategy)
[...]
parameters = {"chainId" : ..., "from": ..., etc}
tx = await my_contract.functions.my_function().build_transaction(parameters)
```
### Full error output
```shell
File "[....]/Executor.py", line 92, in [....]
tx = await my_contract.functions.my_function().build_transaction(parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[....]/.venv/lib/python3.12/site-packages/web3/contract/async_contract.py", line 360, in build_transaction
return await async_build_transaction_for_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[....]/.venv/lib/python3.12/site-packages/web3/contract/utils.py", line 444, in async_build_transaction_for_function
return await async_fill_transaction_defaults(async_w3, prepared_transaction)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[....]/.venv/lib/python3.12/site-packages/web3/_utils/async_transactions.py", line 115, in async_fill_transaction_defaults
strategy_based_gas_price = async_w3.eth.generate_gas_price(transaction)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[....]/.venv/lib/python3.12/site-packages/web3/eth/base_eth.py", line 88, in generate_gas_price
return self._gas_price_strategy(self.w3, transaction_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[....]/.venv/lib/python3.12/site-packages/web3/gas_strategies/time_based.py", line 220, in time_based_gas_price_strategy
if w3.eth.get_block("latest")["number"] == 0:
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
TypeError: 'coroutine' object is not subscriptable
```
### Fill this section in if you know how this could or should be fixed
Change `time_based_gas_price_strategy` to check if w3 node is async or not.
### web3 Version
6.20.0
### Python Version
3.12.3
### Operating System
ubuntu 24
### Output from `pip freeze`
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.