Skip to content

Commit 190a6ac

Browse files
committed
Allow block identifier for Contract.estimateGas
This evens the API with eth.estimateGas.
1 parent 05bbf57 commit 190a6ac

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

web3/contract.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,9 @@ def transact(self, transaction: TxParams=None) -> HexBytes:
996996
**self.kwargs
997997
)
998998

999-
def estimateGas(self, transaction: TxParams=None) -> int:
999+
def estimateGas(
1000+
self, transaction: TxParams=None, block_identifier: BlockIdentifier=None
1001+
) -> int:
10001002
if transaction is None:
10011003
estimate_gas_transaction: TxParams = {}
10021004
else:
@@ -1031,6 +1033,7 @@ def estimateGas(self, transaction: TxParams=None) -> int:
10311033
estimate_gas_transaction,
10321034
self.contract_abi,
10331035
self.abi,
1036+
block_identifier,
10341037
*self.args,
10351038
**self.kwargs
10361039
)
@@ -1588,6 +1591,7 @@ def estimate_gas_for_function(
15881591
transaction: TxParams=None,
15891592
contract_abi: ABI=None,
15901593
fn_abi: ABIFunction=None,
1594+
block_identifier: BlockIdentifier=None,
15911595
*args: Any,
15921596
**kwargs: Any) -> int:
15931597
"""Estimates gas cost a function call would take.
@@ -1606,8 +1610,7 @@ def estimate_gas_for_function(
16061610
fn_kwargs=kwargs,
16071611
)
16081612

1609-
gas_estimate = web3.eth.estimateGas(estimate_transaction)
1610-
return gas_estimate
1613+
return web3.eth.estimateGas(estimate_transaction, block_identifier)
16111614

16121615

16131616
def build_transaction_for_function(

0 commit comments

Comments
 (0)