Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
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