Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Gas Price Strategy #3435

Open
UB18Aux opened this issue Jul 18, 2024 · 1 comment
Open

Async Gas Price Strategy #3435

UB18Aux opened this issue Jul 18, 2024 · 1 comment

Comments

@UB18Aux
Copy link

UB18Aux commented Jul 18, 2024

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

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

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

@fselmo
Copy link
Collaborator

fselmo commented Jul 23, 2024

Seeing as a lot of layer 2 transactions still rely on gasPrice, I think this is a simple enough task still relevant to Ethereum. It's hard to measure how much use these older middleware are getting, and Ethereum moving to EIP-1559 fees sort of put the async-ing of these to the side. I'd review a PR for this if it was submitted though, otherwise I think it'll have to wait a bit until we are freed up with other tasks. Thanks for submitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants