Solidity! Invalid implicit conversion from string memory to bytes memory requested The Next...
Indicator light circuit
Is it professional to write unrelated content in an almost-empty email?
How do I make a variable always equal to the result of some calculations?
Return the Closest Prime Number
How do I transpose the first and deepest levels of an arbitrarily nested array?
How do scammers retract money, while you can’t?
Is there a way to save my career from absolute disaster?
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
Elegant way to replace substring in a regex with optional groups in Python?
How do I go from 300 unfinished/half written blog posts, to published posts?
Should I tutor a student who I know has cheated on their homework?
Why am I allowed to create multiple unique pointers from a single object?
Make solar eclipses exceedingly rare, but still have new moons
What happens if you roll doubles 3 times then land on "Go to jail?"
Novel about a guy who is possessed by the divine essence and the world ends?
How to invert MapIndexed on a ragged structure? How to construct a tree from rules?
Sending manuscript to multiple publishers
How did the Bene Gesserit know how to make a Kwisatz Haderach?
Complex fractions
Why do variable in an inner function return nan when there is the same variable name at the inner function declared after log
What flight has the highest ratio of time difference to flight time?
In excess I'm lethal
Why does standard notation not preserve intervals (visually)
If/When UK leaves the EU, can a future goverment conduct a referendum to join the EU?
Solidity! Invalid implicit conversion from string memory to bytes memory requested
The Next CEO of Stack OverflowWhen to use “View” and “Pure” in place of “Constant”API to “Read Contract Information” to fetch stats of an ICOHow can I split a 56 character input and store them in two Bytes32?Calling mapping (uint ==> bytes32)return 0x0000000This contract does not implement all functions and thus cannot be createdTypeError: This type is only supported in the new experimental ABI encoderHow is gas adjusted for a transfer in solidity?How to handle dynamic size string array in solidity?remix ERC223: This contract does not implement all functions and thus cannot be createdInvalid implicit conversion from bytes32 to bytes memory requestedInvalid implicit conversion from uint256 to bytes memory requested
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
solidity error string bytes data-types
New contributor
add a comment |
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
solidity error string bytes data-types
New contributor
2
It's better if you can copy-paste your code, rather than attaching a screenshot
– Achala Dissanayake
1 hour ago
add a comment |
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
solidity error string bytes data-types
New contributor
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
solidity error string bytes data-types
solidity error string bytes data-types
New contributor
New contributor
edited 43 mins ago
Khalid168
New contributor
asked 2 hours ago
Khalid168Khalid168
184
184
New contributor
New contributor
2
It's better if you can copy-paste your code, rather than attaching a screenshot
– Achala Dissanayake
1 hour ago
add a comment |
2
It's better if you can copy-paste your code, rather than attaching a screenshot
– Achala Dissanayake
1 hour ago
2
2
It's better if you can copy-paste your code, rather than attaching a screenshot
– Achala Dissanayake
1 hour ago
It's better if you can copy-paste your code, rather than attaching a screenshot
– Achala Dissanayake
1 hour ago
add a comment |
2 Answers
2
active
oldest
votes
Argument to sha256
should be in bytes
. But you're passing document
which is a string
. Following would work.
function proofFor(bytes memory document) public pure returns(bytes32) {
return sha256(document);
}
And a side note - your function doesn't need to be view
type since it is not viewing any storage items. This can be made a pure
function which has neither side effects nor storage viewing. More details can be found here.
UPDATE :
If changing string
to bytes
gives errors at other function calls you can either convert them to bytes
as well or else you can cast string
to bytes
as @Mikhail suggested. Then that would be;
function proofFor(string memory document) public pure returns(bytes32) {
return sha256(bytes (document));
}
Thanks for the quick response! after changing the code as u suggested I am getting errors in the other part.
– Khalid168
59 mins ago
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); }
– Khalid168
58 mins ago
I have added the code but seems quite ugly here!
– Khalid168
55 mins ago
1
Thanks a lot for the guidance...Now the problem is solved!
– Khalid168
39 mins ago
1
Yeah done now !
– Khalid168
34 mins ago
|
show 1 more comment
Should probably be
return sha256(bytes (document));
Thanks a lot for help ! It's solved like this
– Khalid168
38 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "642"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Khalid168 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f69055%2fsolidity-invalid-implicit-conversion-from-string-memory-to-bytes-memory-request%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Argument to sha256
should be in bytes
. But you're passing document
which is a string
. Following would work.
function proofFor(bytes memory document) public pure returns(bytes32) {
return sha256(document);
}
And a side note - your function doesn't need to be view
type since it is not viewing any storage items. This can be made a pure
function which has neither side effects nor storage viewing. More details can be found here.
UPDATE :
If changing string
to bytes
gives errors at other function calls you can either convert them to bytes
as well or else you can cast string
to bytes
as @Mikhail suggested. Then that would be;
function proofFor(string memory document) public pure returns(bytes32) {
return sha256(bytes (document));
}
Thanks for the quick response! after changing the code as u suggested I am getting errors in the other part.
– Khalid168
59 mins ago
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); }
– Khalid168
58 mins ago
I have added the code but seems quite ugly here!
– Khalid168
55 mins ago
1
Thanks a lot for the guidance...Now the problem is solved!
– Khalid168
39 mins ago
1
Yeah done now !
– Khalid168
34 mins ago
|
show 1 more comment
Argument to sha256
should be in bytes
. But you're passing document
which is a string
. Following would work.
function proofFor(bytes memory document) public pure returns(bytes32) {
return sha256(document);
}
And a side note - your function doesn't need to be view
type since it is not viewing any storage items. This can be made a pure
function which has neither side effects nor storage viewing. More details can be found here.
UPDATE :
If changing string
to bytes
gives errors at other function calls you can either convert them to bytes
as well or else you can cast string
to bytes
as @Mikhail suggested. Then that would be;
function proofFor(string memory document) public pure returns(bytes32) {
return sha256(bytes (document));
}
Thanks for the quick response! after changing the code as u suggested I am getting errors in the other part.
– Khalid168
59 mins ago
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); }
– Khalid168
58 mins ago
I have added the code but seems quite ugly here!
– Khalid168
55 mins ago
1
Thanks a lot for the guidance...Now the problem is solved!
– Khalid168
39 mins ago
1
Yeah done now !
– Khalid168
34 mins ago
|
show 1 more comment
Argument to sha256
should be in bytes
. But you're passing document
which is a string
. Following would work.
function proofFor(bytes memory document) public pure returns(bytes32) {
return sha256(document);
}
And a side note - your function doesn't need to be view
type since it is not viewing any storage items. This can be made a pure
function which has neither side effects nor storage viewing. More details can be found here.
UPDATE :
If changing string
to bytes
gives errors at other function calls you can either convert them to bytes
as well or else you can cast string
to bytes
as @Mikhail suggested. Then that would be;
function proofFor(string memory document) public pure returns(bytes32) {
return sha256(bytes (document));
}
Argument to sha256
should be in bytes
. But you're passing document
which is a string
. Following would work.
function proofFor(bytes memory document) public pure returns(bytes32) {
return sha256(document);
}
And a side note - your function doesn't need to be view
type since it is not viewing any storage items. This can be made a pure
function which has neither side effects nor storage viewing. More details can be found here.
UPDATE :
If changing string
to bytes
gives errors at other function calls you can either convert them to bytes
as well or else you can cast string
to bytes
as @Mikhail suggested. Then that would be;
function proofFor(string memory document) public pure returns(bytes32) {
return sha256(bytes (document));
}
edited 37 mins ago
answered 1 hour ago
Achala DissanayakeAchala Dissanayake
3,78781629
3,78781629
Thanks for the quick response! after changing the code as u suggested I am getting errors in the other part.
– Khalid168
59 mins ago
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); }
– Khalid168
58 mins ago
I have added the code but seems quite ugly here!
– Khalid168
55 mins ago
1
Thanks a lot for the guidance...Now the problem is solved!
– Khalid168
39 mins ago
1
Yeah done now !
– Khalid168
34 mins ago
|
show 1 more comment
Thanks for the quick response! after changing the code as u suggested I am getting errors in the other part.
– Khalid168
59 mins ago
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); }
– Khalid168
58 mins ago
I have added the code but seems quite ugly here!
– Khalid168
55 mins ago
1
Thanks a lot for the guidance...Now the problem is solved!
– Khalid168
39 mins ago
1
Yeah done now !
– Khalid168
34 mins ago
Thanks for the quick response! after changing the code as u suggested I am getting errors in the other part.
– Khalid168
59 mins ago
Thanks for the quick response! after changing the code as u suggested I am getting errors in the other part.
– Khalid168
59 mins ago
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); }
– Khalid168
58 mins ago
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); }
– Khalid168
58 mins ago
I have added the code but seems quite ugly here!
– Khalid168
55 mins ago
I have added the code but seems quite ugly here!
– Khalid168
55 mins ago
1
1
Thanks a lot for the guidance...Now the problem is solved!
– Khalid168
39 mins ago
Thanks a lot for the guidance...Now the problem is solved!
– Khalid168
39 mins ago
1
1
Yeah done now !
– Khalid168
34 mins ago
Yeah done now !
– Khalid168
34 mins ago
|
show 1 more comment
Should probably be
return sha256(bytes (document));
Thanks a lot for help ! It's solved like this
– Khalid168
38 mins ago
add a comment |
Should probably be
return sha256(bytes (document));
Thanks a lot for help ! It's solved like this
– Khalid168
38 mins ago
add a comment |
Should probably be
return sha256(bytes (document));
Should probably be
return sha256(bytes (document));
answered 50 mins ago
Mikhail VladimirovMikhail Vladimirov
1,003314
1,003314
Thanks a lot for help ! It's solved like this
– Khalid168
38 mins ago
add a comment |
Thanks a lot for help ! It's solved like this
– Khalid168
38 mins ago
Thanks a lot for help ! It's solved like this
– Khalid168
38 mins ago
Thanks a lot for help ! It's solved like this
– Khalid168
38 mins ago
add a comment |
Khalid168 is a new contributor. Be nice, and check out our Code of Conduct.
Khalid168 is a new contributor. Be nice, and check out our Code of Conduct.
Khalid168 is a new contributor. Be nice, and check out our Code of Conduct.
Khalid168 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ethereum Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f69055%2fsolidity-invalid-implicit-conversion-from-string-memory-to-bytes-memory-request%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
It's better if you can copy-paste your code, rather than attaching a screenshot
– Achala Dissanayake
1 hour ago