Hi all I need tho sha256 two strings. I am new to solidity. This is what I've got:
function addressToString(address _addr) public pure returns(string memory)
{
bytes32 value = bytes32(uint256(_addr));
bytes memory alphabet = "0123456789abcdef";
bytes memory str = new bytes(51);
str[0] = '0';
str[1] = 'x';
for (uint256 i = 0; i < 20; i++) {
str[2+i*2] = alphabet[uint8(value[i + 12] >> 4)];
str[3+i*2] = alphabet[uint8(value[i + 12] & 0x0f)];
}
return string(str);
}
function addExam(string memory examHash) public onlyOwner returns (string memory examProfessorHash) {
// Hash the examHash and the professorsAddress together
examsFinalHash = keccak256(abi.encodePacked(examHash, addressToString(msg.sender))); // TYPE ERROR
professorsExam[msg.sender] = examsFinalHash;
return examsFinalHash;
}
I got the addressToString function from this SO answer: Convert address to string . But I still get this error:
Type bytes32 is not implicitly convertible to expected type string storage ref. examsFinalHash = keccak256(abi.encodePacked(examHash, addressToString(msg.sender))); // TYPE ERROR