Forum for discussion of mid, final term and final project

[Dapp] COBrA - Problem with Overloading

[Dapp] COBrA - Problem with Overloading

di ALESSANDRO BERTI -
Numero di risposte: 4
As requested by the specs, the GetMostRated* functions behave in different way according to the number of parameter.
So, in the contract I've something like that:
  1. function getMostRatedByGenre(string _genre, uint8 _cat) external view returns (bytes32);
  2. function getMostRatedByGenre(string _genre) external view returns (bytes32);
The problem is that, when I invoke the 2. function from the frontend, I get the following error:"Error: Invalid number of arguments to Solidity function", while invoking the 1., works
I checked about overloading and I found that is admitted in solidity.
The interesting thing is that, if I invert the order of these function in the ABI, invoking the 1. function , I get no errors but also no value is returned. Invoking the 2. , works

Thanks in advance for any suggestions.

[web3js + ganache]
In riposta a ALESSANDRO BERTI

Re: [Dapp] COBrA - Problem with Overloading

di ORLANDO LEOMBRUNI -

Hi, I don't know if it's correct, but since it's your frontend that will call these functions you can have only the first one and reserve a "special" case (e.g. _cat == 0) to make it behave like the second one. In this way you'll avoid overload problems.

In riposta a ORLANDO LEOMBRUNI

Re: [Dapp] COBrA - Problem with Overloading

di ALESSANDRO BERTI -

Yes, it's a solution but, in this way, I thought that it would not respect the specifications.

In riposta a ALESSANDRO BERTI

Re: [Dapp] COBrA - Problem with Overloading

di DAMIANO DI FRANCESCO MAESA -

[answered during question time] Might be a tool problem. Overloading is correctly supported by Solidity.

In riposta a DAMIANO DI FRANCESCO MAESA

Re: [Dapp] COBrA - Problem with Overloading

di ALESSANDRO BERTI -

I found out that it seems to be a web3js issue. (version 0.20, latest stable version).

There is a workaround exploiting function hashes. Btw it is complicated to manage in this way since web3js (stable version) does not provide any kind of utilities to get the function hash easily. 

Hope it helps.