0

Working on the remix IDE, i cant seem to pass an array of addresses along with an array of uint as parameter to a function. It runs just fine on ethfiddle though and behaves exactly how i expected it to.

It keeps saying on remix, syntax error unexpected token at JSON position 3.

How do I call and test the function set with an array of address and array of value.

here's the code snippet and I am using solidity version 0.5.1 :

contract SimpleStore {
  uint public value;
  address public addr;

  function set(address[] _addr , uint[] _value) public {
    value = _value[0];
    addr = _addr[0];
  }
  function get() public constant returns (uint) {
    return value;
  }
}

I have tried, with quotes without quotes with square brackets without square bracks :( -thanks in advance.

  • I don't think that code should compile under 0.5.1. constant was removed in 0.5.x, right? – smarx Jan 17 at 9:42
  • yes sorry. ethfiddle still uses 0.4.18 where i was trying to test. apologies – Edge Jan 17 at 9:46
1

After updating the code to work with Solidity 0.5.x, the following input for set worked fine for me:

["0x1234567890123456789012345678901234567890"], [1, 2, 3]

After calling set, I checked the values of addr and value to and got 0x12345... and 1, respectively.

For reference, here's the updated code I used with 0.5.2:

pragma solidity 0.5.2;

contract SimpleStore {
    uint256 public value;
    address public addr;

    function set(address[] calldata _addr, uint256[] calldata _value) external {
        value = _value[0];
        addr = _addr[0];
    }

    function get() external view returns (uint256) {
        return value;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.