ethereum-studio icon indicating copy to clipboard operation
ethereum-studio copied to clipboard

Unable to Interact with function which has array parameter

Open Spejbl opened this issue 5 years ago • 1 comments

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

Edit Project

  1. Compile and Deploy to Browser network
  2. Open Interact panel
  3. Try to call update method with 3,2,1
  4. 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. image

Expected result

Update method to be working

Actual result

Not working

Reproducible

100%

Spejbl avatar Nov 15 '19 11:11 Spejbl

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.

filippsen avatar Nov 19 '19 11:11 filippsen