pragma solidity ^0.5
contract ProofOfExistence {
// ... some code here
function proofFor(string memory document) public view returns(bytes32) {
return sha256(document);
}
// ... some more code here
}
Gives following error :
TypeError: Invalid type for argument in function call. Invalid implicit conversion from string memory to bytes memory requested.
I am unable to understand why this error is coming.
UPDATE :
pragma solidity ^0.5;
// Proof of Existence contract, version 3
contract ProofOfExistence3 {
mapping (bytes32 => bool) private proofs;
// store a proof of existence in the contract state
function storeProof(bytes32 proof) public{
proofs[proof] = true;
}
// calculate and store the proof for a document
function notarize(string memory document) public {
**bytes32 proof = proofFor(document);**
storeProof(proof);
}
// helper function to get a document's sha256
function proofFor(bytes memory document) public pure returns (bytes32) {
return sha256(document);
}
// check if a document has been notarized
function checkDocument(string memory document) view public returns (bool) {
**bytes32 proof = proofFor(document);**
return hasProof(proof);
}
// returns true if proof is stored
function hasProof(bytes32 proof) view public returns(bool) {
return proofs[proof];
UPDATE ERROR After the update as suggested I am getting the same error but on the lines having ** ...** this time. Why is it coming now? Thanks