Skip to content

Revisit gas pricing and gas estimation for transactions #225

Description

@jmoreira-valory

The interaction between building a transaction and the TxSettler is problematic at times, as it is unclear what class is the responsible of update what fields.

For example, before PR #224 the transaction builder method to send an ERC20 token from masterEOA was setting the fields

"gas": 1,
"maxFeePerGas": 1,
"maxPriorityFeePerGas": 1,

hoping that it could estimate the gas and then the TxSettler would estimate prices.

However this was not the case, and the gas couldn't be estimated without the correct pricing first. As a result, the following cryptic error appeared:

[2025-10-15 11:38:41,170][WARNING] Unable to retrieve gas estimate: {'code': -32000, 'message': 'failed with 40000000 gas: max fee per gas less than block base fee: address 0x7Bcd993bbA835d7256eDf9BfFCe68C90DC6C38B6, maxFeePerGas: 1, baseFee: 1817'}
{'value': 0, 'chainId': 10, 'from': '0x7Bcd993bbA835d7256eDf9BfFCe68C90DC6C38B6', 'gas': 1, 'maxFeePerGas': 1, 'maxPriorityFeePerGas': 1, 'nonce': 0, 'to': '0xFC2E6e6BCbd49ccf3A5f029c79984372DcBFE527', 'data': '0xa9059cbb00000000000000000000000077b2d88299a40845e8ffbe9edc4bf6e89136c60d0000000000000000000000000000000000000000000000000de0b6b3a7640000'}
Traceback (most recent call last):
  File "/home/user/.cache/pypoetry/virtualenvs/olas-operate-middleware-Sp-CQhXT-py3.11/lib/python3.11/site-packages/autonomy/chain/tx.py", line 183, in transact
    tx_digest = self.ledger_api.send_signed_transaction(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.cache/pypoetry/virtualenvs/olas-operate-middleware-Sp-CQhXT-py3.11/lib/python3.11/site-packages/aea_ledger_ethereum/ethereum.py", line 1298, in send_signed_transaction
    tx_digest = self._try_send_signed_transaction(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.cache/pypoetry/virtualenvs/olas-operate-middleware-Sp-CQhXT-py3.11/lib/python3.11/site-packages/aea/helpers/base.py", line 378, in wrapper
    raise e
  File "/home/user/.cache/pypoetry/virtualenvs/olas-operate-middleware-Sp-CQhXT-py3.11/lib/python3.11/site-packages/aea/helpers/base.py", line 373, in wrapper
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/user/.cache/pypoetry/virtualenvs/olas-operate-middleware-Sp-CQhXT-py3.11/lib/python3.11/site-packages/aea_ledger_ethereum/ethereum.py", line 1316, in _try_send_signed_transaction
    hex_value = self._api.eth.send_raw_transaction(  # pylint: disable=no-member
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.cache/pypoetry/virtualenvs/olas-operate-middleware-Sp-CQhXT-py3.11/lib/python3.11/site-packages/web3/eth/eth.py", line 396, in send_raw_transaction
    return self._send_raw_transaction(transaction)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.cache/pypoetry/virtualenvs/olas-operate-middleware-Sp-CQhXT-py3.11/lib/python3.11/site-packages/web3/module.py", line 75, in caller
    result = w3.manager.request_blocking(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.cache/pypoetry/virtualenvs/olas-operate-middleware-Sp-CQhXT-py3.11/lib/python3.11/site-packages/web3/manager.py", line 330, in request_blocking
    return self.formatted_response(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.cache/pypoetry/virtualenvs/olas-operate-middleware-Sp-CQhXT-py3.11/lib/python3.11/site-packages/web3/manager.py", line 293, in formatted_response
    raise ValueError(error)
ValueError: {'code': -32000, 'message': 'intrinsic gas too low: gas 1, minimum needed 21632'}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/user/git/olas-operate-middleware/ztest-daemon-07.py", line 1232, in <module>
    main()
  File "/home/user/git/olas-operate-middleware/ztest-daemon-07.py", line 1051, in main
    test_raw_operate()
  File "/home/user/git/olas-operate-middleware/ztest-daemon-07.py", line 900, in test_raw_operate
    wallet.transfer_erc20(
  File "/home/user/git/olas-operate-middleware/operate/wallet/master.py", line 467, in transfer_erc20
    return self._transfer_erc20_from_eoa(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/git/olas-operate-middleware/operate/wallet/master.py", line 366, in _transfer_erc20_from_eoa
    tx_receipt = tx_settler.transact(
                 ^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.cache/pypoetry/virtualenvs/olas-operate-middleware-Sp-CQhXT-py3.11/lib/python3.11/site-packages/autonomy/chain/tx.py", line 200, in transact
    raise ChainInteractionError(error) from e
autonomy.chain.exceptions.ChainInteractionError: {'code': -32000, 'message': 'intrinsic gas too low: gas 1, minimum needed 21632'}

The adopted solution is to (1) estimate pricing correctly, and (2) try to estimate the gas. This strategy has been applied in the bridging module and has given very to none issues related to that.

It should be revised that this gas / gas pricing handling is properly managed for all transactions in an homogeneous way across the middleware (possibly this responsibility should go to the TxSettler).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions