Storing document/file in blockchain

  • 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.

  • 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.

    _The 1 MB size limit is for the Bitcoin's blockchain._ Limit for what?

    @niksmac Size limit for each Block. Updated my answer

  • 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.

    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.

    Sure, just ask a mod to move this conversation to chat.

    Thank you so much. I can't go to the chat now it's the week end but I'll call you later.

    Hi, I'm here to talk with you. Tell me when you are ok

    But I can't start the chat because we need more comments to trigger 'Let us continue this discussion in chat'

    Ok, I'm adding a few comments of my own and then we'll move to chat.

    The chat should pop up any second now.

    We'll trim these comments out as soon as it does.

    sorry I was busy. Are you here today ?

    I added a post here -> http://ethereum.stackexchange.com/q/10226/5170 Because I don't think we can chat if this is not my post.

  • 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.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM