Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contract method override types issues #6650

Closed
luu-alex opened this issue Dec 8, 2023 · 2 comments · Fixed by #6942
Closed

contract method override types issues #6650

luu-alex opened this issue Dec 8, 2023 · 2 comments · Fixed by #6942
Assignees
Labels
4.x 4.0 related Bug Addressing a bug

Comments

@luu-alex
Copy link
Contributor

luu-alex commented Dec 8, 2023

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

  1. [First step]
  2. [Second step]
  3. [and so on...]

Logs

Environment

@luu-alex luu-alex added Bug Addressing a bug 4.x 4.0 related labels Dec 8, 2023
@sunidhiii
Copy link

sunidhiii commented Jan 3, 2024

You need to specify the signature of the method you're calling like this:
contract. methods.getPenaltyBP['getPenaltyBP(address)'] ("0xaceaEcB820Be3f147FF40d1C221B25F10ee8dd92").call()

@Muhammad-Altabba
Copy link
Contributor

Muhammad-Altabba commented Mar 24, 2024

Hi @avkos ,
I think I fixed the source of issue at #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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants