I am new to etheruem, I would like to create a smart contract for keeping document data.

From 2 designs below, can I know the pro and con of each one, please?

  1. put the array of raw JSON data to the blockchain
items = [
   field1: value1,
   field2: value2,
   fieldN: valueN
  1. put only hash of JSON data to the blockchain
items = ["hash of object1", "hash of object2", ...]

What are the pro and con both designs above in term of fee (when insert or update), query speed?

and if my system has up to 100 million documents. Can the etheruem blockchain hold all of my data?


  • FYI on the 100 million documents. Storing a single 32-byte hash costs 20,000 gas. 20,000 gas/document * 100 million documents * 2 gwei/gas (current gas price) * $150/ether ~= $600,000. So yes, you could technically store that many hashes, but the cost would be quite high.
    – user19510
    Commented Jan 13, 2019 at 16:38

2 Answers 2


Storage on blockchain is expensive. So, only saving the hash on-chain and storing the actual data off-chain is better. This way you can cheaply store your data and ensure its integrity (because you are keeping the hash of the actual data).

If the system has 100 million documents on-chain, it means you at least spent tens of thousands of dollars for storage. And I think you wouldn't like to do this.

  • thanks for the feedback. Can I ask a few questions please? the fee of each method is different? saving only the hash use lower gas?
    – Alongkorn
    Commented Jan 13, 2019 at 15:58
  • 1
    The more data you save the more gas you pay. So if you only save hashes it means you will save small amount of data. (Hashes are tiny compared to actual data most of the time)
    – ferit
    Commented Jan 13, 2019 at 16:00
  • thanks, @ferit, one more question, please. If my system has up to 100 million documents. Can the etheruem blockchain hold all of my data?
    – Alongkorn
    Commented Jan 13, 2019 at 16:06
  • 1
    Yeah, it can hold, there is no limitation on this. But I'm almost sure that will cost you astronomically. Note that you can't store them at once as each block has a gas limit.
    – ferit
    Commented Jan 13, 2019 at 16:19

As you are probably aware of, storing data in Ethereum is really expensive. With some quick calculations (based on What is the cost to store 1KB, 10KB, 100KB worth of data into the ethereum blockchain?) it would currently cost something like 5 million dollars to store a GB of data into Ethereum. So, you can see how much it would cost in your case to store the JSONs (probably a lot).

So, one typical alternative is to store the actual data in IPFS and only store hash values into Ethereum. This is a lot cheaper alternative; approximate prices are:

  • Storing one hash (for example QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4 which is 0x98ebda79fb50d75642261f9cfc0f210b53ddee5eabdbd304ff0afaa4543afd47 in bytes32) in the cheapest possible way (at least as far as I know) (bytes32 argument into an indexed log entry) costs 24662 gas which translates into $0.005 with current prices.
  • Storing multiple hashes at the same time gets somewhat cheaper. Storing 10 bytes32 entries into log entries costs 67222 gas which is $0.013. (Using an array of bytes32 - so you can just use more entries).

Also, keep in mind that someone has to host your data in IPFS. Most likely that would be your own nodes, so you have to pay for their upkeep.

As for the reading costs, they are free. Reading data does not cost anything, so you don't need to worry about that. Also it's very fast as the data comes directly from your node.

As for your last question: there are basically no upper boundaries for how much data contracts can store, so yes, in theory a contract could store all your data.

  • thanks, I think that instead of using IPFS, saving to own mongodb may be better and more privacy.
    – Alongkorn
    Commented Jan 13, 2019 at 16:08
  • 1
    Of course, all centralized options are easier and cheaper. Just depends on what you need. Commented Jan 13, 2019 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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