How do I call Contract methods with overloaded signatures?
See original GitHub issueThe contract https://etherscan.io/address/0x226159d592E2b063810a10Ebf6dcbADA94Ed68b8#code has a function addr
where second argument is optional. It generates the following ABI (fragment):
const abi = [
{
"constant":true,
"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],
"name":"addr",
"outputs":[{"internalType":"address","name":"","type":"address"}],
"payable":false,
"stateMutability":"view",
"type":"function",
},
{
"constant":true,
"inputs":[
{"internalType":"bytes32","name":"node","type":"bytes32"},
{"internalType":"uint256","name":"coinType","type":"uint256"}],
"name":"addr",
"outputs":[{"internalType":"bytes","name":"","type":"bytes"}],
"payable":false,
"stateMutability":"view",
"type":"function",
},
]
new ethers.utils.Interface(abi).encodeFunctionData('addr', [
'0x981bb41ff8d6a8d71f71f2f44261af41c3279ad75a57b303f263b11646b28b05',
144,
]);
Which causes an error when encoding arguments:
/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/logger/lib/index.js:179
var error = new Error(message);
^
Error: multiple matching functions (argument="name", value="addr", code=INVALID_ARGUMENT, version=abi/5.0.1)
at Logger.makeError (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/logger/lib/index.js:179:21)
at Logger.throwError (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/logger/lib/index.js:188:20)
at Logger.throwArgumentError (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/logger/lib/index.js:191:21)
at Interface.getFunction (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/abi/lib/interface.js:179:24)
at Interface.encodeFunctionData (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/abi/lib/interface.js:257:37)
at Object.<anonymous> (/Users/bogdan/makabu/unstoppable/resolution/tmp/test2.ts:27:33)
at Module._compile (internal/modules/cjs/loader.js:1201:30)
at Module.m._compile (/Users/bogdan/.nvm/versions/node/v14.5.0/lib/node_modules/ts-node/src/index.ts:858:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
at Object.require.extensions.<computed> [as .ts] (/Users/bogdan/.nvm/versions/node/v14.5.0/lib/node_modules/ts-node/src/index.ts:861:12)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
ethers - call an overloaded function with a specific signer
assuming a signer called 'user' and a contract called 'Foo' with function 'bar' await Foo.connect(user).bar();.
Read more >How to use overloaded function from smart contract with wagmi?
This should pass the function signature to the underlying ethers call. Share.
Read more >Learn Solidity lesson 24. Function overloading, fallback and ...
The data we send to a contract in a transaction (or call) is called payload. The payload usually contains the signature of the...
Read more >Polymorphism and Function Overloading in Solidity
Contract polymorphism supports calling the child contract function by using the instance of parent contracts. pragma solidity ^0.4.19;contract ...
Read more >A Simple Explanation of Function Overloading in TypeScript
The second approach is to use the function overloading feature. I recommend it when the function signature is relatively complex and has ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ricmoo Was just wondering if it’s possible for methods like
foo(bytes2)
andfoo(bytes)
in same contract can be called in this fashion or am I missing something:This way I think it could be explicit which method will be called and ethers.js would not require to guess (and I agree guessing would lead to unintended behavior).
I think this has been answered to everyone’s satisfaction? So, I’m going to close it, but if not, please feel free to re-open.
Thanks! 😃