1

currently i am learning ipfs and ethereum based blockchain technology,I wanted to know can we store data on ethereum blockchain and yes then how. and also wanted to know how exactly ipfs work for blockchain.

1

As an addition to the answer of Tudor Constantin:

IPFS is pretty much a decentralized P2P Filesystem.

Here is a quick summary of how IPFS basically works:

  • If you add a file you receive the corresponding hash of that file which is also the unique reference to it
  • The file is then stored on different Nodes running IPFS
  • Everyone who knows the hash of the file will be able to view/fetch it. If the data is sensitive you need to add somekind of encryption
  • If you add the same file multiple times it will only be stored as one entry because the hash will be always the same. If you however change the file and read it you will obviously receive a new reference since the hash changes

This is a really neat way to store data in a decentralized manner because you can just put all your payload (for example large JSON-Files with your applications data) in IPFS and only store the reference to that file on the blockchain instead of putting all the data into the blockchain which is (as Tudor already stated) quite expensive.

So to summarize:

To safe data:

  • post your payload to IPFS and receive the reference to your file
  • store the reference in your smart contract on the blockchain

To fetch your data:

  • fetch the reference from your smart contract
  • fetch your data from IPFS

Use this as a pattern:

IPFS stores the actual content and Ethereum stores the immutable history of references.

2

Yes, we can store any data we want on the the blockchain. It's expensive to do so, but it's possible. That's why it's recommended to store just the minimum on the blockchain and the rest using another form of storage (decentralized or not), like (as you mentioned) IPFS, or Ethereum's Swarm.

This looks like a nice tutorial for working with IPFS from a dApp.

You can think of IPFS/swarm as the storage layer of your dApp, where you can host your .js/html/css files and the user uploaded content, while the smart contract code as the business logic layer of your dApp.

  • When you send files to Infura how long will they be stored for in their IPFS cluster? – cleanunicorn Apr 25 '18 at 8:01
  • @cleanunicorn, that's a good question and I couldn't find any details online regarding this. I guess the only way to find out is to either ask them directly, or to try and see. Anyway, if their cache-time is not long enough, one always has the possibility to host their own IPFS node. – Tudor Constantin Apr 25 '18 at 8:13

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