I want to maintain a datastore of key value pairs. For example, I have users of my dapp input their favorite food. I would like to map their account to the food name. It is my understanding that I can do this through a smart contract or I could store it on swarm. What are the distinctions between data stores on swarm and those that are within a smart contract? Do I get more privacy by storing my data on swarm rather than through EVM state?


Storing your data in a smart contract is expensive, it is uneconomic to save larger amounts of data to a smart contract. You may have better control over how (not who) your data will be accessed with a smart contract. As you send data with a transaction though, all nodes receive it, so for privacy, you'd have to encrypt the data.

In swarm, you upload your content which then gets chopped into pieces, with each chunk sent to different nodes for storage based on their hash - basically the hash is also the address of the chunk. Everyone who has the hash can retrieve and read the content. Thus, in swarm too, if you want privacy, you need to encrypt your data and manage the keys (the swarm team is working on a built-in encryption facility).

However, storing in swarm is much cheaper, and suited for any size of data. Currently, it's even free, as the SWAP accounting protocol is being implemented. When it will be enabled, payment is due to consume the data, and nodes serving data will be paid (micro-payments). Also, your data will be served by nodes based on popularity.

Unpopular data (low or no request frequency) may be purged by nodes though, but you can insure it with an upfront payment.

Finally, by participating in the swarm network, you may also end up being paid for serving content, offsetting (or even outperforming) your insurance costs.

Swarm is still alpha though, so you shouldn't use it yet for mission critical apps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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