14

I have this smart contract:

pragma solidity 0.5;
pragma experimental ABIEncoderV2;
contract TestStruct {

      struct User {
        string name;
        uint256 age;
     }

    mapping (bytes32 => User) users;

    function addUsers (User [] memory _users) public {

        for (uint i = 0; i < _users.length; i++) {

           bytes32 hash = keccak256(abi.encode(_users[i].name));
           users[hash] = _users[i];

        }
    }

    function getUser (string memory username) public view returns (User memory) {

        bytes32 hash = keccak256(abi.encode(username));

        return users[hash];
    }
}

I want to test it using remix IDE, But I didn't find the write way to pass the array of struct in remix UI

I try this enter image description here

And I got this error:

transact to TestStruct.addUsers errored: Error encoding arguments: SyntaxError: JSON.parse: expected property name or '}' at line 1 column 4 of the JSON data  
maroodb
  • 1,111
  • 1
  • 10
  • 32

2 Answers2

11

Your function takes an array of structures as an argument:

enter image description here

Richard Horrocks
  • 37,835
  • 13
  • 87
  • 144
0

Declare the value directly and replace the brackets with square brackets

[["maro",20]]

more detail: HERE