1

I am working on a project in solidity where I want to generate a SHA256 hash value for the document. So which means when I pass a file to a function the function should return the hash value.

can anyone please help me do so. Thanks in advance.

  • Show your code (on-chain and off-chain) please. – goodvibration May 20 at 6:19
1

The document can be converted to a base64 encoded string. You can then hash the string to get the document hash. Hope it helps. Thanks.

  • how to do it in solidity can you please help. I mean how to convert a document to base64 – karthik yadav May 20 at 9:48
  • it is ideal you store only the hash in smart contract. since the data will be public. you can convert the document using javascript. You can then send the string to your contract. For more, you can see stackoverflow.com/questions/36280818/… – Sanjay S B May 20 at 10:23
  • Okay understood, thanks a lot – karthik yadav May 20 at 11:44
  • you are welcome – Sanjay S B May 20 at 11:45
  • Hi, had a question. When I convert the file to base64 I get a big string(50 lines of string) when I pass the string as an argument to the function in solidity it can't handle that string, is there any way I can optimise the big string to short that it can be passed to the function in solidity. – karthik yadav May 21 at 7:50

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.