ethereum-studio
ethereum-studio copied to clipboard
Unable to Interact with function which has array parameter
Environment/Browser
Live
Description
When any function has array as parameter, it's unable to Interact with it. Example code:
contract HelloWorld {
uint256[] public message;
function update(uint256[] memory newMessage) public {
message = newMessage;
}
}
Steps to reproduce
- Compile and Deploy to Browser network
- Open Interact panel
- Try to call update method with
3,2,1
-
Error: Invalid number of arguments to Solidity function
Another use case but similar issue
contract HelloWorld {
uint256[] public message;
string public message2;
function update(uint256[] memory newMessage, string memory newMessage2) public {
message = newMessage;
message2 = newMessage2;
}
}
Since there is an array in arguments, the first issue will occur, but then there is an another issue that if you try to call update method with 3,2,1, Hello world
which should result in message = [3,2,1]
and message2 = "Hello World"
, but since the values are separated by comma, the application will think that there are 4 parameters instead of 2.
One way of solving such issue, could be to bring back the functionality from Lab. Which is to have for each parameter a separate input. Instead of having every parameter in one input separated by comma.
Expected result
Update method to be working
Actual result
Not working
Reproducible
100%
Passing array arguments as comma-separated values such as 3,2,1
was expected to be available.
Very important observation about multiple function arguments. An alternative way to solve it would be to change the calling convention, but that would incur in changes to constructor parameters as well to harmonize all array interactions. Exposing each value as a separate field is a clean approach, which has also been battle-tested before as you mentioned.