@@ -1114,7 +1114,7 @@ def _get_call_txparams(self, transaction: Optional[TxParams] = None) -> TxParams
1114
1114
1115
1115
return call_transaction
1116
1116
1117
- def transact (self , transaction : Optional [TxParams ] = None ) -> HexBytes :
1117
+ def _transact (self , transaction : Optional [TxParams ] = None ) -> TxParams :
1118
1118
if transaction is None :
1119
1119
transact_transaction : TxParams = {}
1120
1120
else :
@@ -1139,22 +1139,11 @@ def transact(self, transaction: Optional[TxParams] = None) -> HexBytes:
1139
1139
raise ValueError (
1140
1140
"Please ensure that this contract instance has an address."
1141
1141
)
1142
+ return transact_transaction
1142
1143
1143
- return transact_with_contract_function (
1144
- self .address ,
1145
- self .w3 ,
1146
- self .function_identifier ,
1147
- transact_transaction ,
1148
- self .contract_abi ,
1149
- self .abi ,
1150
- * self .args ,
1151
- ** self .kwargs
1152
- )
1153
-
1154
- def estimateGas (
1155
- self , transaction : Optional [TxParams ] = None ,
1156
- block_identifier : Optional [BlockIdentifier ] = None
1157
- ) -> int :
1144
+ def _estimate_gas (
1145
+ self , transaction : Optional [TxParams ] = None
1146
+ ) -> TxParams :
1158
1147
if transaction is None :
1159
1148
estimate_gas_transaction : TxParams = {}
1160
1149
else :
@@ -1181,18 +1170,7 @@ def estimateGas(
1181
1170
raise ValueError (
1182
1171
"Please ensure that this contract instance has an address."
1183
1172
)
1184
-
1185
- return estimate_gas_for_function (
1186
- self .address ,
1187
- self .w3 ,
1188
- self .function_identifier ,
1189
- estimate_gas_transaction ,
1190
- self .contract_abi ,
1191
- self .abi ,
1192
- block_identifier ,
1193
- * self .args ,
1194
- ** self .kwargs
1195
- )
1173
+ return estimate_gas_transaction
1196
1174
1197
1175
def buildTransaction (self , transaction : Optional [TxParams ] = None ) -> TxParams :
1198
1176
"""
@@ -1315,6 +1293,43 @@ def call(self, transaction: Optional[TxParams] = None,
1315
1293
def factory (cls , class_name : str , ** kwargs : Any ) -> 'ContractFunction' :
1316
1294
return PropertyCheckingFactory (class_name , (cls ,), kwargs )(kwargs .get ('abi' ))
1317
1295
1296
+ def transact (self , transaction : Optional [TxParams ] = None ) -> HexBytes :
1297
+ setup_transaction = self ._transact (transaction )
1298
+ return transact_with_contract_function (
1299
+ self .address ,
1300
+ self .w3 ,
1301
+ self .function_identifier ,
1302
+ setup_transaction ,
1303
+ self .contract_abi ,
1304
+ self .abi ,
1305
+ * self .args ,
1306
+ ** self .kwargs
1307
+ )
1308
+
1309
+ def estimate_gas (
1310
+ self , transaction : Optional [TxParams ] = None ,
1311
+ block_identifier : Optional [BlockIdentifier ] = None
1312
+ ) -> int :
1313
+ setup_transaction = self ._estimate_gas (transaction )
1314
+ return estimate_gas_for_function (
1315
+ self .address ,
1316
+ self .w3 ,
1317
+ self .function_identifier ,
1318
+ setup_transaction ,
1319
+ self .contract_abi ,
1320
+ self .abi ,
1321
+ block_identifier ,
1322
+ * self .args ,
1323
+ ** self .kwargs
1324
+ )
1325
+
1326
+ @deprecated_for ("estimate_gas" )
1327
+ def estimateGas (
1328
+ self , transaction : Optional [TxParams ] = None ,
1329
+ block_identifier : Optional [BlockIdentifier ] = None
1330
+ ) -> int :
1331
+ return self .estimate_gas (transaction , block_identifier )
1332
+
1318
1333
1319
1334
class AsyncContractFunction (BaseContractFunction ):
1320
1335
@@ -1385,6 +1400,36 @@ async def call(
1385
1400
def factory (cls , class_name : str , ** kwargs : Any ) -> 'AsyncContractFunction' :
1386
1401
return PropertyCheckingFactory (class_name , (cls ,), kwargs )(kwargs .get ('abi' ))
1387
1402
1403
+ async def transact (self , transaction : Optional [TxParams ] = None ) -> HexBytes :
1404
+ setup_transaction = self ._transact (transaction )
1405
+ return await async_transact_with_contract_function (
1406
+ self .address ,
1407
+ self .w3 ,
1408
+ self .function_identifier ,
1409
+ setup_transaction ,
1410
+ self .contract_abi ,
1411
+ self .abi ,
1412
+ * self .args ,
1413
+ ** self .kwargs
1414
+ )
1415
+
1416
+ async def estimate_gas (
1417
+ self , transaction : Optional [TxParams ] = None ,
1418
+ block_identifier : Optional [BlockIdentifier ] = None
1419
+ ) -> int :
1420
+ setup_transaction = self ._estimate_gas (transaction )
1421
+ return await async_estimate_gas_for_function (
1422
+ self .address ,
1423
+ self .w3 ,
1424
+ self .function_identifier ,
1425
+ setup_transaction ,
1426
+ self .contract_abi ,
1427
+ self .abi ,
1428
+ block_identifier ,
1429
+ * self .args ,
1430
+ ** self .kwargs
1431
+ )
1432
+
1388
1433
1389
1434
class BaseContractEvent :
1390
1435
"""Base class for contract events
@@ -2091,6 +2136,34 @@ def transact_with_contract_function(
2091
2136
return txn_hash
2092
2137
2093
2138
2139
+ async def async_transact_with_contract_function (
2140
+ address : ChecksumAddress ,
2141
+ w3 : 'Web3' ,
2142
+ function_name : Optional [FunctionIdentifier ] = None ,
2143
+ transaction : Optional [TxParams ] = None ,
2144
+ contract_abi : Optional [ABI ] = None ,
2145
+ fn_abi : Optional [ABIFunction ] = None ,
2146
+ * args : Any ,
2147
+ ** kwargs : Any ) -> HexBytes :
2148
+ """
2149
+ Helper function for interacting with a contract function by sending a
2150
+ transaction.
2151
+ """
2152
+ transact_transaction = prepare_transaction (
2153
+ address ,
2154
+ w3 ,
2155
+ fn_identifier = function_name ,
2156
+ contract_abi = contract_abi ,
2157
+ transaction = transaction ,
2158
+ fn_abi = fn_abi ,
2159
+ fn_args = args ,
2160
+ fn_kwargs = kwargs ,
2161
+ )
2162
+
2163
+ txn_hash = await w3 .eth .send_transaction (transact_transaction ) # type: ignore
2164
+ return txn_hash
2165
+
2166
+
2094
2167
def estimate_gas_for_function (
2095
2168
address : ChecksumAddress ,
2096
2169
w3 : 'Web3' ,
@@ -2120,6 +2193,35 @@ def estimate_gas_for_function(
2120
2193
return w3 .eth .estimate_gas (estimate_transaction , block_identifier )
2121
2194
2122
2195
2196
+ async def async_estimate_gas_for_function (
2197
+ address : ChecksumAddress ,
2198
+ w3 : 'Web3' ,
2199
+ fn_identifier : Optional [FunctionIdentifier ] = None ,
2200
+ transaction : Optional [TxParams ] = None ,
2201
+ contract_abi : Optional [ABI ] = None ,
2202
+ fn_abi : Optional [ABIFunction ] = None ,
2203
+ block_identifier : Optional [BlockIdentifier ] = None ,
2204
+ * args : Any ,
2205
+ ** kwargs : Any ) -> int :
2206
+ """Estimates gas cost a function call would take.
2207
+
2208
+ Don't call this directly, instead use :meth:`Contract.estimateGas`
2209
+ on your contract instance.
2210
+ """
2211
+ estimate_transaction = prepare_transaction (
2212
+ address ,
2213
+ w3 ,
2214
+ fn_identifier = fn_identifier ,
2215
+ contract_abi = contract_abi ,
2216
+ fn_abi = fn_abi ,
2217
+ transaction = transaction ,
2218
+ fn_args = args ,
2219
+ fn_kwargs = kwargs ,
2220
+ )
2221
+
2222
+ return await w3 .eth .estimate_gas (estimate_transaction , block_identifier ) # type: ignore
2223
+
2224
+
2123
2225
def build_transaction_for_function (
2124
2226
address : ChecksumAddress ,
2125
2227
w3 : 'Web3' ,
0 commit comments