0

In this code, I want to send an array of bytes32 and store them in the struct but I get the error which is

 TypeError: Type string memory[8] memory is not implicitly convertible to expected type bytes32[8] storage ref. i.hash= [ "0x9ba99edb","0x9ba99edb","0x9ba99edb","0x9ba99edb","0x9ba99edb","0x9ba99edb","0x9ba99edb","0x9ba99edb"]; ^---------------------------------------"

my function code and related code are:

pragma solidity >=0.6.0 <0.7.0;
 struct Info {
    address creator;
    bytes16 id;
    // address owner;
    // address contractAddress;
    string detail;
    bytes32[8]  hash ;
}
uint16 public infoSize = 0;
mapping(bytes16 => Info) public infos;
bytes16[] public infosId;
function newInfo(string memory detail  )
    public
    returns (
        bytes16 
    )
{
    // Info storage  i = infos[infoId];
    bytes16 infoId = randomId();
    // console.logBytes16(infoId);
    Info storage i = infos[infoId];
    i.detail = detail;
    i.id = infoId;
    i.creator = msg.sender;
    i.hash= [ "0x9ba99edb","0x9ba99edb","0x9ba99edb","0x9ba99edb","0x9ba99edb","0x9ba99edb","0x9ba99edb","0x9ba99edb"];
    infosId.push(infoId);
     infoSize=infoSize+1;
    return infoId;
}

I don't know how can I fix it. my next step is to pass this array through function as a parameter

2
  • for (uint256 n = 0; n < i.hash.length; n++) i.hash[n] = "0x9ba99edb"; – goodvibration Dec 22 '20 at 19:52
  • Or if you want to pass it as input to the function, then you can simply add bytes32[8] memory hash to the parameter list, and then do i.hash = hash. – goodvibration Dec 22 '20 at 20:06

Your Answer

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

Browse other questions tagged or ask your own question.