0

I would like to upload a file to my UI and then produce a hash of it so I could later store it on Ethereum. Here is the code I am using to upload the file:

<div>
   <label for="file input">Submit your file here</label>
   <input type="file"">
</div>

How can I create a hash of any file on the UI side so I can later submit this hash onto Ethereum?

closed as off-topic by Nicolas Massart, Achala Dissanayake, Ismael, shane, flygoing Jun 27 at 14:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Ethereum, the decentralized application platform and smart contract enabled blockchain, within the scope defined in the help center." – Nicolas Massart, Ismael, shane, flygoing
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Please take your time to get acquainted with some implementation of web3 (web3.js probably most suitable in this case). – goodvibration Jun 21 at 13:53
1

First you need to write and deploy a simple storage smart-contract (with solidity and truffle), then you need to use the web3js library to connect to the blockchain and later to call your function in the smart-contract --> send a transaction to upload the hash of the file in your deployed smart contract

The web3 library provide a function to calcuate the hash of a given string so you should read your file as string or convert it somehow to string and call web3.utils.keccak256(string) to get the hash

Not the answer you're looking for? Browse other questions tagged or ask your own question.