0

My contract is as follows:

pragma solidity ^0.4.21;
contract try {
    mapping (address=>bytes32[10]) Map;

    function try(){}

    function fill_map(bytes32[10] _attributes) public  {
            Map[msg.sender].push(_attributes);
    }

    function get_map(address id) view public returns (bytes32[10]){
      return Map[id];
    }

}

The error I get is:

Member “push” not found or not visible after argument-dependent lookup in bytes32[10] storage reference Map[msg.sender].push(_attributes)

I also tried inserting the data with a loop as follows:

    for(uint i=0;i<10;i++)
    {
        Map[msg.sender].push(_attributes[i]);
    }

Also results in the same error.

0

You have to assign the data directly

function fill_map(bytes32[10] _attributes) public  {
        Map[msg.sender] = _attributes;
}

Also try is a reserved keyword and the compilation will fail. You have to use another name for your contract.

1

The syntax to insert data in a mapping (key => value) Map is

Map[key] = value 

In your case it is Map[msg.sender] = _attributes

push() function inserts data into array but not into map.

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.