11

I am planning to do a POC on blockchain for uploading and verifying documents. I was wondering if I can store a complete document in blockchain. After some research on net most of the example, I found keep the hash of the document in blockchain because of 1 MB size limitation. So, the question here is - Is it possible to store large file - doc/pdf/audio in the blockchain?

Thanks in Advance.

2

3 Answers 3

20

The 1 MB size limit per Block is for the Bitcoin's blockchain. In Ethereum, there is theoretically no limit for the block size. However, blockchain is not meant for data storage and storing large documents will be very expensive. Here are some instances where people hacked into the Bitcoin Blockchain and stored some unexpected data. You would have to compress and store the doc/pdf/audio in Hexadecimal format.

That said, many blockchain-like solutions designed just to store data were developed recently. STORJ seems to be famous and well developed. Filecoin is another such solution which is yet to materialize. Enigma is one more initiative which is being developed in the MIT Media Lab.

Like you mentioned, blockchain might be used to maintain a Distributed Hash Table(DHT) which contains hashes of the data files stored off-chain. This is to ensure integrity of data.

These are the costs for storing data on Ethereum public blockchain as of June 7th, 2016:

Storage costs:

This is Solidity code for creating a contract with 1 Kilo Byte of data.

contract Storage { byte[1024] data; function Storage() { for (uint i = 0; i < 1024; i++) { data[i] = 'A';}}}

If we run this code in the online compiler, we get an estimated transaction cost of 5925085 gas. The gas price today is 23731285772 Wei (10^18 Wei = 1 Ether = $15). So, storing 1 Kilo Byte of data in the public blockchain, as per conversion rates on June 7th is approximately $2.11.

Reading costs:

Similarly, reading 1 Kilo Byte of data costs 284396 gas, which is approximately $0.1.

This price might increase if there is an increase in the Gas value or Ether value.

More information about gas prices can be found at “Appendix G. Fee Schedule” of the Ethereum yellow paper.

2
  • 1
    The 1 MB size limit is for the Bitcoin's blockchain. Limit for what?
    – niksmac
    Commented Aug 8, 2016 at 16:35
  • @niksmac Size limit for each Block. Updated my answer
    – galahad
    Commented Aug 8, 2016 at 16:45
2

Yes, it is possible. The simplest way would be to define a contract with two attributes, an address used for access control (so that only an account that you control can write to the contract) and a byte array for the actual storage container:

contract Storage {

   address owner = 0xdeadbeef...; // <= define the address you control (have the private key to)

   bytes32[] storageContainer;

   function pushByte(bytes32 b) {
      storageContainer.push(b);
   }

}

You don't really need a getter method as it is sufficient to synchronize with the block chain in order to retrieve the data stored in the contract.

10
  • I'm a ethereum beginner. Could you help me in private chat ? I have to put a file in the blockchain. But I don't know where to start.
    – John
    Commented Nov 18, 2016 at 15:36
  • Sure, just ask a mod to move this conversation to chat.
    – Sebi
    Commented Nov 18, 2016 at 17:55
  • Thank you so much. I can't go to the chat now it's the week end but I'll call you later.
    – John
    Commented Nov 18, 2016 at 19:44
  • Hi, I'm here to talk with you. Tell me when you are ok
    – John
    Commented Nov 21, 2016 at 9:10
  • But I can't start the chat because we need more comments to trigger 'Let us continue this discussion in chat'
    – John
    Commented Nov 21, 2016 at 9:11
2

Cost of storing one kilobyte is 640k gas.

Default cost of gas is 0.02 microether.

Storing one kilobyte is 0.01280000 ethers.

Storing one megabyte is around 12 ethers, or $120, assuming 1 ETH is $10 (currently it is more).

I hope your documents or sentence size or pay well. Instead, you should store files in alternative storage-oriented blockchains as other answers mention.

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