@@ -102,7 +102,51 @@ def __init__(
102
102
self .erc1155 = self ._detect_erc_1155 ()
103
103
104
104
def call (self , fn : str , * args ) -> Any :
105
- return self ._contract_wrapper .call (fn , * args )
105
+ func = cast (ContractFunction , getattr (self .functions , fn , None ))
106
+ if func is None :
107
+ raise Exception (
108
+ f"Function { fn } not found on contract { self .get_address ()} . "
109
+ + "Check your dashboard for the list of available functions."
110
+ )
111
+
112
+ # We need this to set params properly on func + throws good errors
113
+ func .args = args
114
+ func .kwargs = {}
115
+ func ._set_function_info ()
116
+
117
+ if len (func .abi ["inputs" ]) != len (args ):
118
+ signature = (
119
+ "("
120
+ + ", " .join (
121
+ [(i ["name" ] + ": " + i ["type" ]) for i in func .abi ["inputs" ]]
122
+ )
123
+ + ")"
124
+ )
125
+ raise Exception (
126
+ f"Function { fn } expects { len (func .arguments )} arguments, "
127
+ f"but { len (args )} were provided.\n Expected function signature: { signature } "
128
+ )
129
+
130
+ if func .abi ["stateMutability" ] == "view" or func .abi ["stateMutability" ] == "pure" :
131
+ return func (* args ).call ()
132
+ else :
133
+ provider = self ._contract_wrapper .get_provider ()
134
+ signer = self ._contract_wrapper .get_signer ()
135
+
136
+ if signer is None :
137
+ raise NoSignerException
138
+
139
+ nonce = provider .eth .get_transaction_count (signer .address ) # type: ignore
140
+
141
+ tx = func (* args ).buildTransaction (
142
+ TxParams (gas_price = provider .eth .gas_price ).as_dict ()
143
+ )
144
+ tx ["nonce" ] = nonce
145
+
146
+ signed_tx = signer .sign_transaction (tx ) # type: ignore
147
+ tx_hash = provider .eth .send_raw_transaction (signed_tx .rawTransaction )
148
+
149
+ return provider .eth .wait_for_transaction_receipt (tx_hash )
106
150
107
151
"""
108
152
INTERNAL FUNCTIONS
0 commit comments