@@ -118,8 +118,6 @@ class BaseEth(Module):
118
118
_default_block : BlockIdentifier = "latest"
119
119
_default_chain_id : Optional [int ] = None
120
120
gasPriceStrategy = None
121
- defaultContractFactory : Type [Union [Contract , AsyncContract ,
122
- ConciseContract , ContractCaller , AsyncContractCaller ]] = Contract
123
121
124
122
_gas_price : Method [Callable [[], Wei ]] = Method (
125
123
RPC .eth_gasPrice ,
@@ -374,6 +372,7 @@ def set_contract_factory(
374
372
375
373
class AsyncEth (BaseEth ):
376
374
is_async = True
375
+ defaultContractFactory : Type [Union [AsyncContract , AsyncContractCaller ]] = AsyncContract
377
376
378
377
@property
379
378
async def accounts (self ) -> Tuple [ChecksumAddress ]:
@@ -586,10 +585,29 @@ async def call(
586
585
) -> Union [bytes , bytearray ]:
587
586
return await self ._call (transaction , block_identifier , state_override )
588
587
588
+ @overload
589
+ def contract (self , address : None = None , ** kwargs : Any ) -> Type [AsyncContract ]: ... # noqa: E704,E501
590
+
591
+ @overload # noqa: F811
592
+ def contract (self , address : Union [Address , ChecksumAddress , ENS ], ** kwargs : Any ) -> AsyncContract : ... # noqa: E704,E501
593
+
594
+ def contract ( # noqa: F811
595
+ self , address : Optional [Union [Address , ChecksumAddress , ENS ]] = None , ** kwargs : Any
596
+ ) -> Union [Type [AsyncContract ], AsyncContract ]:
597
+ ContractFactoryClass = kwargs .pop ('ContractFactoryClass' , self .defaultContractFactory )
598
+
599
+ ContractFactory = ContractFactoryClass .factory (self .w3 , ** kwargs )
600
+
601
+ if address :
602
+ return ContractFactory (address )
603
+ else :
604
+ return ContractFactory
605
+
589
606
590
607
class Eth (BaseEth ):
591
608
account = Account ()
592
609
iban = Iban
610
+ defaultContractFactory : Type [Union [Contract , ConciseContract , ContractCaller ]] = Contract
593
611
594
612
def namereg (self ) -> NoReturn :
595
613
raise NotImplementedError ()
@@ -997,6 +1015,24 @@ def getCompilers(self) -> NoReturn:
997
1015
is_property = True ,
998
1016
)
999
1017
1018
+ @overload
1019
+ def contract (self , address : None = None , ** kwargs : Any ) -> Type [Contract ]: ... # noqa: E704,E501
1020
+
1021
+ @overload # noqa: F811
1022
+ def contract (self , address : Union [Address , ChecksumAddress , ENS ], ** kwargs : Any ) -> Contract : ... # noqa: E704,E501
1023
+
1024
+ def contract ( # noqa: F811
1025
+ self , address : Optional [Union [Address , ChecksumAddress , ENS ]] = None , ** kwargs : Any
1026
+ ) -> Union [Type [Contract ], Contract ]:
1027
+ ContractFactoryClass = kwargs .pop ('ContractFactoryClass' , self .defaultContractFactory )
1028
+
1029
+ ContractFactory = ContractFactoryClass .factory (self .w3 , ** kwargs )
1030
+
1031
+ if address :
1032
+ return ContractFactory (address )
1033
+ else :
1034
+ return ContractFactory
1035
+
1000
1036
@deprecated_for ("generate_gas_price" )
1001
1037
def generateGasPrice (self , transaction_params : Optional [TxParams ] = None ) -> Optional [Wei ]:
1002
1038
return self ._generate_gas_price (transaction_params )
0 commit comments