1

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  
1

Your function takes an array of structures as an argument:

enter image description here

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.