Skip to content

Commit a5b8a04

Browse files
dbfreempacrob
authored and
pacrob
committed
Feature/asyncify contract (ethereum#2439)
* removed buildTransaction and estimateGas
1 parent 5887604 commit a5b8a04

File tree

4 files changed

+14
-59
lines changed

4 files changed

+14
-59
lines changed

docs/contracts.rst

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,6 @@ Each Contract Factory exposes the following methods.
244244
>>> txn_receipt['contractAddress']
245245
'0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'
246246
247-
.. py:classmethod:: Contract.constructor(*args, **kwargs).estimateGas(transaction=None, block_identifier=None)
248-
:noindex:
249-
250-
.. warning:: Deprecated: This method is deprecated in favor of :py:meth:`Contract.constructor(*args, **kwargs).estimate_gas`
251-
252247
.. py:classmethod:: Contract.constructor(*args, **kwargs).estimate_gas(transaction=None, block_identifier=None)
253248
:noindex:
254249

@@ -272,11 +267,6 @@ Each Contract Factory exposes the following methods.
272267
>>> token_contract.constructor(web3.eth.coinbase, 12345).estimate_gas()
273268
12563
274269
275-
.. py:classmethod:: Contract.constructor(*args, **kwargs).buildTransaction(transaction=None)
276-
:noindex:
277-
278-
.. warning:: Deprecated: This method is deprecated in favor of :py:meth:`Contract.constructor(*args, **kwargs).build_transaction`
279-
280270
.. py:classmethod:: Contract.constructor(*args, **kwargs).build_transaction(transaction=None)
281271
:noindex:
282272

@@ -843,10 +833,6 @@ Methods
843833
a "missing trie node" error, because Ethereum node may have purged the past state from its database.
844834
`More information about archival nodes here <https://ethereum.stackexchange.com/a/84200/620>`_.
845835

846-
.. py:method:: ContractFunction.estimateGas(transaction, block_identifier=None)
847-
848-
.. warning:: Deprecated: This method is deprecated in favor of :class:`~estimate_gas`
849-
850836
.. py:method:: ContractFunction.estimate_gas(transaction, block_identifier=None)
851837
852838
Call a contract function, executing the transaction locally using the
@@ -874,10 +860,6 @@ Methods
874860
The parameter ``block_identifier`` is not enabled in geth nodes,
875861
hence passing a value of ``block_identifier`` when connected to a geth
876862
nodes would result in an error like: ``ValueError: {'code': -32602, 'message': 'too many arguments, want at most 1'}``
877-
878-
.. py:method:: ContractFunction.buildTransaction(transaction)
879-
880-
.. warning:: Deprecated: This method is deprecated in favor of :class:`~build_transaction`
881863

882864
.. py:method:: ContractFunction.build_transaction(transaction)
883865
@@ -941,15 +923,15 @@ Fallback Function
941923
Call fallback function, executing the transaction locally using the
942924
``eth_call`` API. This will not create a new public transaction.
943925

944-
.. py:method:: Contract.fallback.estimateGas(transaction)
926+
.. py:method:: Contract.fallback.estimate_gas(transaction)
945927
946928
Call fallback function and return the gas estimation.
947929

948930
.. py:method:: Contract.fallback.transact(transaction)
949931
950932
Execute fallback function by sending a new public transaction.
951933

952-
.. py:method:: Contract.fallback.buildTransaction(transaction)
934+
.. py:method:: Contract.fallback.build_transaction(transaction)
953935
954936
Builds a transaction dictionary based on the contract fallback function call.
955937

docs/examples.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ The following example demonstrates a few things:
361361
362362
store_var_contract = w3.eth.contract(address=address, abi=contract_interface["abi"])
363363
364-
gas_estimate = store_var_contract.functions.setVar(255).estimateGas()
364+
gas_estimate = store_var_contract.functions.setVar(255).estimate_gas()
365365
print(f'Gas estimate to transact with setVar: {gas_estimate}')
366366
367367
if gas_estimate < 100000:
@@ -674,7 +674,7 @@ Just remember that you have to sign all transactions locally, as infura does not
674674

675675
.. code-block:: python
676676
677-
transaction = contract.functions.function_Name(params).buildTransaction()
677+
transaction = contract.functions.function_Name(params).build_transaction()
678678
transaction.update({ 'gas' : appropriate_gas_amount })
679679
transaction.update({ 'nonce' : w3.eth.get_transaction_count('Your_Wallet_Address') })
680680
signed_tx = w3.eth.account.sign_transaction(transaction, private_key)

docs/web3.eth.account.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ To sign a transaction locally that will invoke a smart contract:
356356
>>> unicorn_txn = unicorns.functions.transfer(
357357
... '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359',
358358
... 1,
359-
... ).buildTransaction({
359+
... ).build_transaction({
360360
... 'chainId': 1,
361361
... 'gas': 70000,
362362
... 'maxFeePerGas': w3.toWei('2', 'gwei'),

web3/contract.py

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -868,22 +868,6 @@ def build_transaction(self, transaction: Optional[TxParams] = None) -> TxParams:
868868
built_transaction = self._build_transaction(transaction)
869869
return transactions.fill_transaction_defaults(self.w3, built_transaction)
870870

871-
@combomethod
872-
@deprecated_for("build_transaction")
873-
def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams:
874-
"""
875-
Build the transaction dictionary without sending
876-
"""
877-
return self.build_transaction(transaction)
878-
879-
@combomethod
880-
@deprecated_for("estimate_gas")
881-
def estimateGas(
882-
self, transaction: Optional[TxParams] = None,
883-
block_identifier: Optional[BlockIdentifier] = None
884-
) -> int:
885-
return self.estimate_gas(transaction, block_identifier)
886-
887871
@combomethod
888872
def estimate_gas(
889873
self, transaction: Optional[TxParams] = None,
@@ -924,7 +908,7 @@ async def estimate_gas(
924908

925909

926910
class ConciseMethod:
927-
ALLOWED_MODIFIERS = {'call', 'estimateGas', 'transact', 'buildTransaction'}
911+
ALLOWED_MODIFIERS = {'call', 'estimate_gas', 'transact', 'build_transaction'}
928912

929913
def __init__(
930914
self, function: 'ContractFunction',
@@ -1178,9 +1162,9 @@ def _estimate_gas(
11781162
estimate_gas_transaction = cast(TxParams, dict(**transaction))
11791163

11801164
if 'data' in estimate_gas_transaction:
1181-
raise ValueError("Cannot set 'data' field in estimateGas transaction")
1165+
raise ValueError("Cannot set 'data' field in estimate_gas transaction")
11821166
if 'to' in estimate_gas_transaction:
1183-
raise ValueError("Cannot set to in estimateGas transaction")
1167+
raise ValueError("Cannot set to in estimate_gas transaction")
11841168

11851169
if self.address:
11861170
estimate_gas_transaction.setdefault('to', self.address)
@@ -1191,7 +1175,7 @@ def _estimate_gas(
11911175
if 'to' not in estimate_gas_transaction:
11921176
if isinstance(self, type):
11931177
raise ValueError(
1194-
"When using `Contract.estimateGas` from a contract factory "
1178+
"When using `Contract.estimate_gas` from a contract factory "
11951179
"you must provide a `to` address with the transaction"
11961180
)
11971181
else:
@@ -1211,7 +1195,7 @@ def _build_transaction(self, transaction: Optional[TxParams] = None) -> TxParams
12111195

12121196
if not self.address and 'to' not in built_transaction:
12131197
raise ValueError(
1214-
"When using `ContractFunction.buildTransaction` from a contract factory "
1198+
"When using `ContractFunction.build_transaction` from a contract factory "
12151199
"you must provide a `to` address with the transaction"
12161200
)
12171201
if self.address and 'to' in built_transaction:
@@ -1339,13 +1323,6 @@ def estimate_gas(
13391323
**self.kwargs
13401324
)
13411325

1342-
@deprecated_for("estimate_gas")
1343-
def estimateGas(
1344-
self, transaction: Optional[TxParams] = None,
1345-
block_identifier: Optional[BlockIdentifier] = None
1346-
) -> int:
1347-
return self.estimate_gas(transaction, block_identifier)
1348-
13491326
def build_transaction(self, transaction: Optional[TxParams] = None) -> TxParams:
13501327

13511328
built_transaction = self._build_transaction(transaction)
@@ -1360,10 +1337,6 @@ def build_transaction(self, transaction: Optional[TxParams] = None) -> TxParams:
13601337
**self.kwargs
13611338
)
13621339

1363-
@deprecated_for("build_transaction")
1364-
def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams:
1365-
return self.build_transaction(transaction)
1366-
13671340

13681341
class AsyncContractFunction(BaseContractFunction):
13691342

@@ -2224,7 +2197,7 @@ def estimate_gas_for_function(
22242197
**kwargs: Any) -> int:
22252198
"""Estimates gas cost a function call would take.
22262199
2227-
Don't call this directly, instead use :meth:`Contract.estimateGas`
2200+
Don't call this directly, instead use :meth:`Contract.estimate_gas`
22282201
on your contract instance.
22292202
"""
22302203
estimate_transaction = prepare_transaction(
@@ -2253,7 +2226,7 @@ async def async_estimate_gas_for_function(
22532226
**kwargs: Any) -> int:
22542227
"""Estimates gas cost a function call would take.
22552228
2256-
Don't call this directly, instead use :meth:`Contract.estimateGas`
2229+
Don't call this directly, instead use :meth:`Contract.estimate_gas`
22572230
on your contract instance.
22582231
"""
22592232
estimate_transaction = prepare_transaction(
@@ -2281,7 +2254,7 @@ def build_transaction_for_function(
22812254
**kwargs: Any) -> TxParams:
22822255
"""Builds a dictionary with the fields required to make the given transaction
22832256
2284-
Don't call this directly, instead use :meth:`Contract.buildTransaction`
2257+
Don't call this directly, instead use :meth:`Contract.build_transaction`
22852258
on your contract instance.
22862259
"""
22872260
prepared_transaction = prepare_transaction(
@@ -2311,7 +2284,7 @@ async def async_build_transaction_for_function(
23112284
**kwargs: Any) -> TxParams:
23122285
"""Builds a dictionary with the fields required to make the given transaction
23132286
2314-
Don't call this directly, instead use :meth:`Contract.buildTransaction`
2287+
Don't call this directly, instead use :meth:`Contract.build_transaction`
23152288
on your contract instance.
23162289
"""
23172290
prepared_transaction = prepare_transaction(

0 commit comments

Comments
 (0)