As storing persistent data on blockchain is costly due to the storage operation being gas-expensive, what are the solutions to store mutable data outside the realm of blockchain from within a smart contract? I heard about IPFS and Swarm, but didn't really understand how they interface as a storage layer with a smart contract. Let's say we are to design an imaginary banking application (DApp) that should handle a million customers. We need to read/write the customer information including the account balance in a persistent storage. The business logic is implemented in a smart contract. But, how do we deal with this huge volume of data in a storage later?

1 Answer 1


In this case you will use the Blockchain ( using a smart contract) as a source of truth that for each document will provide an unique identifier (the document's hash). Assume for example, that your app registers deals between parties and the deal involves a contract document, you can use an smart contract to save the deal details including the hash of the contract document. In the event that is necessary to verify the authenticity of the document, taking the hash of it and comparing it with the hash stored in the smart contract will be sufficient proof that the document has or hasn't been modified. If the document is modified "legally" your app will register the hash of the modified doc. Like this you can store your data anywere, the advantage of IPFS is that the storage is decentralized but the idea is the same when you think about the smart contract.

If your app produces many transaction per hour, probably is necessary to look for a more efficient solution, or maybe to change the logic in such way that you only save the hash of an snapshot of your database (root of the Merkel tree of your data) at particular times, instead of saving individually the hashes of each document.

Hope that this helps

  • What I understand is the data is stored on to IPFS outside the scope of the smart contract and then the has is passed to it. My question is the other way round. If my contract updates the account balance of a customer, is there any way to store that data to IPFS from inside the smart contract code (Solidity)?
    – sherlock
    Oct 29, 2019 at 17:14
  • But is the change is already made in the smart contract, you have basically stored the new value. In that case, you do not need external storage.
    – Jaime
    Oct 29, 2019 at 21:04
  • I want to avoid the storage of the smart contract, rather update the balance in some external storage layer like IPFS. Is it possible to trigger an update from inside Solidity (smart contract code)?
    – sherlock
    Oct 29, 2019 at 21:25
  • 1
    In your approach, you are sending the data to the smart contract, you are not saving the data in the smart contract storage but the data is recorded in the blockchain. under these circumstances you only need to implement an off-chain system that reads the trasnactions and determined the correct balances. you do not need extrenal storage because you are submitting the data to the blockchain anyway.
    – Jaime
    Oct 29, 2019 at 21:39

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.