So I have two function with the same name but different parameter in my solidity smart contract
functionName(args1)
and
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
When I try to use wagmi useContractWrite to call the first function with:
const functionWrite = useContractWrite({
...ContractInstance,
functionName: 'functionName',
args: [args1],
});
or calling second 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}"
Does anyone know how to use overloaded function with 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.