web3.js
web3.js copied to clipboard
contract method override types issues
We have an issue with the library with contract methods that are overriden, when there are multiple methods with the same name and different types, _createContractMethod will map the abi methods so that it will only use the first method type
issue is around here: https://github.com/web3/web3.js/blob/4.x/packages/web3-eth-contract/src/contract.ts#L1065
for example:
[
...,
{
inputs: [{ internalType: 'uint256', name: '_startTime', type: 'uint256' }],
name: 'getPenaltyBP',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ internalType: 'address', name: '_user', type: 'address' }],
name: 'getPenaltyBP',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
]
calling contract.methods.getPenaltyBP("0xaceaEcB820Be3f147FF40d1C221B25F10ee8dd92").call().then(console.log) will result in the address converted into a uint and being encoded improperly
Expected behavior
contract.methods.getPenaltyBP("0xaceaEcB820Be3f147FF40d1C221B25F10ee8dd92").call().then(console.log) method should be encoded as an address
Actual behavior
Steps to reproduce the behavior
- [First step]
- [Second step]
- [and so on...]
Logs
Environment
You need to specify the signature of the method you're calling like this: contract. methods.getPenaltyBP['getPenaltyBP(address)'] ("0xaceaEcB820Be3f147FF40d1C221B25F10ee8dd92").call()
Hi @avkos , I think I fixed the source of issue at https://github.com/web3/web3.js/pull/6922/ and now the developer can call using the following when there is ambiguity with the method overlading:
contract.methods['getPenaltyBP(address)'] ("0xaceaEcB820Be3f147FF40d1C221B25F10ee8dd92").call()
However, for the mentioned case where a value could be an address and still also be handled as a UInt or a string, I think it is not a good idea to handle as an address, because it could be also a string for example. And there are many cases like the ambiguity between uint8 and uint256 for example.
And because our library accepts a hex for uint as well as for string in addition to the possibility of being an address, I suggest to through an error in this case. But I think this might be a breaking chage. I referred to this at: https://github.com/web3/web3.js/pull/6922/files#r1536734512
Or what do you think?