Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit d58c81d

Browse files
authored
Fix contract.call (#132)
1 parent 52c30bf commit d58c81d

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ packages = [
66
{include = "thirdweb"},
77
]
88
readme = "README.md"
9-
version = "3.0.2"
9+
version = "3.0.3"
1010

1111
[tool.poetry.dependencies]
1212
python = ">=3.7.1"

thirdweb/contracts/custom.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,51 @@ def __init__(
102102
self.erc1155 = self._detect_erc_1155()
103103

104104
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.\nExpected 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)
106150

107151
"""
108152
INTERNAL FUNCTIONS

0 commit comments

Comments
 (0)