Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use IPFS to store application state (as a backend for dApp)?

I am just starting with IPFS and Ethereum. We are building a dApp (mobile) and planning to replace the standard API & DB layer with IPFS and Ethereum. So, after lots of reading I have the following questions,

  1. Making dApp directly talk to IPFS (via IPFS APIs) to store data (app. data or files) and fetch data. ie, completely replacing the API layer with IPFS seems possible, but is there any issue with this approach? can we live without APIs at all?

  2. If point 1 is possible, accessing the file data is straight forward but how to access the app. data in IPFS (e.g: what is the recommended structure to store and retrieve, how to store different user data etc)?

  3. I understand that the data added to IPFS is available publicly, how can we protect that data and make it available only for the specific client? As I understand that there is no public/private key mechanism in IPFS?

  4. When we store videos in IPFS, to stream the video in the client, do we need to use CDNs and I am not sure how to do that in a decentralised solution.

  5. Is there any option available in IPFS to perform a task (e.g.: running a script) automatically when some events are triggered or upon commanded by the client apps?

  6. Is there any known performance issues with IPFS when finding and fetching the data from a node?

  7. Any suggestion on the tools and frameworks available to achieve the above approach?

Thanks in advance.

like image 718
KayKay Avatar asked Oct 16 '22 11:10

KayKay


1 Answers

Making dApp directly talk to IPFS (via IPFS APIs) to store data (app. data or files) and fetch data. ie, completely replacing the API layer with IPFS seems possible, but is there any issue with this approach? can we live without APIs at all?

Depends on what you want to do. But with content-addressed storage, IPNS, and ipfs pubsub you have all components to write some very complex applications that do not use any centralised service.

Especially pubsub is still experimental. But the latest version of IPFS, 0.4.18, contains a new pubsub implementation that should be much more scalable.

If point 1 is possible, accessing the file data is straight forward but how to access the app. data in IPFS (e.g: what is the recommended structure to store and retrieve, how to store different user data etc)?

You just publish your app under an IPNS key that you control. Assuming we are talking about javascript/typescript apps here, you can package them just like you would usually do, using tools like webpack, and the put the final artefact on IPFS and publish using IPNS.

I understand that the data added to IPFS is available publicly, how can we protect that data and make it available only for the specific client? As I understand that there is no public/private key mechanism in IPFS?

Each IPFS node has a public/private key pair. You can use that to encrypt messages for a node or to sign messages from a node. This is used in IPNS. You can have more than one keypair per node.

When we store videos in IPFS, to stream the video in the client, do we need to use CDNs and I am not sure how to do that in a decentralised solution.

IPFS basically is a CDN. So you would not have to use an extra CDN. You could also use the Cloudflare IPFS gateway.

Work to make IPFS very efficient for distribution of very large files such as videos is currently ongoing. There are apps already using this, such as D.Tube

Is there any option available in IPFS to perform a task (e.g.: running a script) automatically when some events are triggered or upon commanded by the client apps?

No. IPFS/libp2p is basically the network stack for the distributed web. If you want functionality such as automatic execution of scripts triggered by events, you would either have to write it yourself on top of IPFS pubsub, or use more high level middleware such as Orbit DB.

Is there any known performance issues with IPFS when finding and fetching the data from a node?

Yes. IPFS is still pretty young. E.g. there is an issue with the distribution of large files from many peers that is currently being worked on. Many companies are using IPFS in production, but you will be living on the bleeding edge and have occasional issues.

Any suggestion on the tools and frameworks available to achieve the above approach?

Difficult to answer without knowledge of the overall goal and the skill level of the developers. If you want maximum performance, you will have to use IPFS or libp2p directly. To get started, it might make sense to build on something like OrbitDB.

There are also lots of examples for JS-IPFS to get started.

like image 110
Rüdiger Klaehn Avatar answered Oct 28 '22 23:10

Rüdiger Klaehn