[英]How to use overloaded function from smart contract with wagmi?
So I have two function with the same name but different parameter in my solidity smart contract functionName(args1)
and functionName(args1, args2)
所以我有两个 function 在我的solidity智能合约
functionName(args1)
和functionName(args1, args2)
中具有相同的名称但不同的参数
And because of this function overloading, the ABI of the smart contract has 2 function with exactly the same name, functionName
with 1 argument and functionName
with 2 arguments并且由于这个 function 重载,智能合约的 ABI 有 2 个 function 名称完全相同,
functionName
有 1 个参数, functionName
有 2 个 ZDBC11CAA5BDA99F77E6FB4DAD882E
When I try to use wagmi useContractWrite to call the first function with:当我尝试使用 wagmi useContractWrite 调用第一个 function 时:
const functionWrite = useContractWrite({
...ContractInstance,
functionName: 'functionName',
args: [args1],
});
or calling second function或致电第二个 function
const functionWrite = useContractWrite({
...ContractInstance,
functionName: 'functionName',
args: [args1, args2],
});
It seems wagmi didn't detect the function because of the duplicate name and it gave me this error: 'functionName' doesn't exist in interface for contract "{my contract address}"
由于名称重复,wagmi 似乎没有检测到 function,它给了我这个错误:
'functionName' doesn't exist in interface for contract "{my contract address}"
Does anyone know how to use overloaded function with wagmi?有谁知道如何将重载的 function 与 wagmi 一起使用?
I was looking for this and just did some trial and error to figure it out.我一直在寻找这个,只是做了一些试验和错误来弄清楚。 Since I got it working, I figured I would come back and give you and others an answer.
自从我得到它的工作,我想我会回来给你和其他人一个答案。
const functionWrite = useContractWrite({
...ContractInstance,
functionName: 'functionName(arg1Type, arg2Type)',
args: [args1, args2],
});
This should pass the function signature to the underlying ethers call.这应该将 function 签名传递给底层的 ethers 调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.