How to store a hash of some data in a currently publicly available blockchain?

store data in ethereum blockchain
how to retrieve data from blockchain
how can blockchain be used to store data
how to create a blockchain database
how is blockchain technology currently being used?
how to read data from ethereum blockchain
blockchain can be stored as flat file
how is blockchain technology being used?

I have read that blockchains aren't good at storing large files. But you can create a hash of a file and somehow store that in the blockchain, they say. How do I do that? What API or service should I be looking at? Can I do it on, or does it need to be some special "parameterized" blockchain service of some sort?

In the blogs I've seen touting how cool it is where you can store your data in mysql but store the hash in the blockchain, they don't show how you actually nitty-gritty get the hash into the blockchain, or even what services are recommended to do this. Where is the API? What field do I pass to the hash into?

This is what I think the frontend would look like:

     hashedData = web3.utils.sha3(JSON.stringify(certificate));
contracts.mycontract.deployed().then(function(result) {
           return result.createCertificate(public_addresskey,hashedData,{ from: account }); //get logged in public key from metamask 
         }).then(function(result) {
            //send post request to backend to create db entry

         }).catch(function(err) {
           // show error to the user.

The contract might look something like the sketch below.

There is a struct to contain everything but the id. A mapping from hash => Cert for random access (using the hash as id) and a certList to enumerate the certificates in case the hash isn't known. That should not happen because it emits events for each important state change. You would probably want to protect the newCert() function with onlyOwner, a whiteList or role-based access control.

To "confirm" a cert, the recipient confirms by signing a transaction. The existence of a true in this field shows that the user mentioned did indeed sign because there is no other way for this to occur.

pragma solidity 0.5.1;

contract Certificates {

    struct Cert {
        address recipient;
        bool confirmed;

    mapping(bytes32 => Cert) public certs;
    bytes32[] public certList;

    event LogNewCert(address sender, bytes32 cert, address recipient);
    event LogConfirmed(address sender, bytes32 cert);

    function isCert(bytes32 cert) public view returns(bool isIndeed) {
        if(cert == 0) return false;
        return certs[cert].recipient != address(0);

    function createCert(bytes32 cert, address recipient) public {
        require(recipient != address(0));
        Cert storage c = certs[cert];
        c.recipient = recipient;
        emit LogNewCert(msg.sender, cert, recipient);

    function confirmCert(bytes32 cert) public {
        require(certs[cert].recipient == msg.sender);
        require(certs[cert].confirmed == false);
        certs[cert].confirmed = true;
        emit LogConfirmed(msg.sender, cert);

    function isUserCert(bytes32 cert, address user) public view returns(bool) {
        if(!isCert(cert)) return false;
        if(certs[cert].recipient != user) return false;
        return certs[cert].confirmed;

Storing Data on the Blockchain: The Developers Guide, Storing data on the blockchain is not as simple as it sounds. A hash is a generated string, that is computed using our data is input. data we get back some transparency, because the data is now publicly accessible again. This Transaction payment information is usually publicly available with its own transaction TXID or HASH ID, date of transaction, amount sent, receiving bitcoin wallet etc. There are alternative sites that can offer Bitcoin wallet and can also search the Blockchain explorer, for example, Coinbase etc.

The short answer is: "Use Ethereum smart contract with events and don't store hash values in the contract."

On Etherscan your may find a complete contract for the storage of hash values in Ethereum: HashValueManager. As you will see in this code example - things are a bit more complex. You have to manage access rights and here the cost was not important (this contract has been designed for a syndicated blockchain)

Actually it is very expensive to store hash data in a blockchain. When you use an Ethereum contract to store the hash data, you have to pay about 0.03 Euro (depending on the ETH and Gas prize) for each transaction.

It would be a better option not to store the hash value in the contract. A much more cheaper alternative is to emit indexed events in a smart contract and query the events (this is very fast). Information about the events are stored in a bloom filter of the mined block and will be readable forever. The only disadvantage is that an event can't be read from within the contract (but this is not your business logic)

You may read more details here about events and how to fetch them in an application : "ETHEREUM EVENT EXPLORER FOR SMART CONTRACTS" (disclaimer: this article is my blog). Also the complete source code is available on GitHub.

How can blockchain be used as a database to store data?, Primarily a blockchain is a data structure of - surprise, surprise - blocks of data. Currently decentralized blockchain applications have few options to store data. The data directory is the location where Bitcoin’s data files are stored, including the wallet data file. There is a 1 MB size limit per Block that can be stored in the Bitcoin’s blockchain.

For store there is existing several ways. More interesting question: how would you planning to retrieve and use your data? I assume, you planning go retrieve by some way. Otherwise, if no retrieve - there is no sense to store.

OK. there is 2 ways to store your hashes. I will demonstrate examples within emercoin blockchain.

  1. Store as OP_RETURN UTXO. To do this, use the command "createrawtransaction" by using JSON RPC API or command line interface. Just specify "data" for define UTXO, contains your hash. In this case, data will be stored within one of unspendable transaction output. This saved data is not indexed, and you need to save TXID for future retrieval. Otherwise, you need rescan the entire blockchain for retrieve your data.

  2. You can store data within indexed NVS-subsystem (Name-Value Storage). to upload, you need run the command "name_new", where hash can be your search key. In future, you can quickly retrieve your data by search key with commands "name_show" or "name_history". Also, there is possible to save your data as DNS-records within emerDNS, and retrieve by DNS UDP requests by protocol RFC1035.

For details, see the doc:

Decentralized Computing Using Blockchain Technologies and Smart , By leveraging the potential of distributed public ledger system, blockchain ordered data points are grouped into individual storage units called blocks. ordered blocks thus forms a publicly available, easy to verify mechanism for protecting of hash functions associated with the blockchain makes any illegal modification  A blockchain is a linked list of transactions which contains data and a hash pointer to the previous block in the blockchain. A given blockchain functions based on the verification of a hash and digital signatures. Hashing is the process that the blockchain uses to confirm its state. Each transaction requires one or more digital signatures.

Blockchain for Distributed Systems Security, Cloud computing allows users to remotely store their data in the cloud and as key management, in the cloud computing environment have several challenges. The protection of data exchanged within the cloud infrastructure currently on the security of hash functions and the availability of a public ledger (blockchain). Off-chain storage refers to the storing of data off the blockchain, for example, in a relational database. The on-chain data can store metadata about this off-chain data, together with pointers to where the actual data resides, and hash codes that may be used to verify the integrity of the off-chain data.

No, you don't store data on the blockchain - here's why, Storing any serious amount of data on a public blockchain like If building a blockchain from scratch is beyond your current scope, the Each file is addressed by its unique hash and can be stored in many copies across the network. so even if some of them malfunction, your data will remain accessible. You can store the location of the data on the blockchain. Just define an asset in the Composer CTO field and give it a String property with the file location. There are code examples in the Playground for reading and writing to the autogenerated Asset Registry. You will also get a RESTful endpoint to read and write this data.

How does blockchain work in 7 steps, First of all; a blockchain is a digital concept to store data. It will be publicly available to anyone who wants to see it ever again, in exactly the way it This block of data now gets a signature for this specific string of data. A cryptographic hash function is a very complicated formula that takes any string of input and turns it  Storing information on a blockchain, in addition to the mere transaction data, could have significant benefits. In general, blockchains offer a highly secure and highly available, independent and censorship-free storage of information by their very nature.

  • I have to ask, why? What are you trying to accomplish?