Skip to content

Fix gas types #2330

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

Merged
merged 4 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/middleware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Buffered Gas Estimate
This adds a gas estimate to transactions if ``gas`` is not present in the transaction
parameters. Sets gas to:
``min(w3.eth.estimate_gas + gas_buffer, gas_limit)``
where the gas_buffer default is 100,000 Wei
where the gas_buffer default is 100,000

HTTPRequestRetry
~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 2 additions & 0 deletions newsfragments/2330.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fix types for ``gas``, and ``gasLimit`` (``Wei`` to ``int``)
- Fix types for ``effectiveGasPrice``, (``int`` to ``Wei``)
9 changes: 4 additions & 5 deletions web3/_utils/async_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from web3.types import (
BlockIdentifier,
TxParams,
Wei,
)

if TYPE_CHECKING:
Expand All @@ -17,16 +16,16 @@

async def get_block_gas_limit(
web3_eth: "AsyncEth", block_identifier: Optional[BlockIdentifier] = None
) -> Wei:
) -> int:
if block_identifier is None:
block_identifier = await web3_eth.block_number
block = await web3_eth.get_block(block_identifier)
return block['gasLimit']


async def get_buffered_gas_estimate(
web3: "Web3", transaction: TxParams, gas_buffer: Wei = Wei(100000)
) -> Wei:
web3: "Web3", transaction: TxParams, gas_buffer: int = 100000
) -> int:
gas_estimate_transaction = cast(TxParams, dict(**transaction))

gas_estimate = await web3.eth.estimate_gas(gas_estimate_transaction) # type: ignore
Expand All @@ -40,4 +39,4 @@ async def get_buffered_gas_estimate(
"limit: {1}".format(gas_estimate, gas_limit)
)

return Wei(min(gas_limit, gas_estimate + gas_buffer))
return min(gas_limit, gas_estimate + gas_buffer)
Loading