I am new to blockchain development and following some tutorials I have created a DApp that allows a user to save and view information. Now, i want to let another user view that saved information but for that new user have to pay some ether. Basically, I want the main user have the right to let a new user view their data. So, what can I do to implement this in Ethereum?
You can implement a smart contract where people will have to pay money to retrieve some content from the smart contract. You can also implement this so that the user whose content it is gets the money that is paid.
However, all data on the blockchain and all data inside smart contracts can be viewed by anyone at all times, as this is the nature of blockchain: all data is public. So if someone can access the data for free, there would be no reason for them to pay money to the smart contract to view the data.
It is difficult.
As suggested by Hamza, you may store the encrypted data on-chain. There are challenges, though.
- Data size limitation. Storage costs Ether. Even with unlimited Ether, a single transaction cannot spend more than the block gas limit. One may argue the encrypted data can be split into multiple transactions. This only adds complexity and the overall price doesn't change.
- Access control. This solution needs an (unchangeable) symmetric encryption key among all authorised parties. There is no way to revoke permission. Expect the content to be paid by one customer and leaked forever.
An improved version would be to store the encrypted file on IPFS, and the access permission list on-chain. This is similar to the ideas in this paper. This possibly allows easier permission control, e.g. the decryption software always look at the latest access list. Although, in my opinion, it remains to be seen how it works in reality.
- How to permanently delete a file on IPFS? (I don't know much about IPFS so this isn't a problem, would be great if someone can confirm).
- If the content is valuable enough, it might worthwhile for a miner to craft two blocks, one includes the payment transaction (thus getting access), and the other doesn't include it, with the hope that the "without" block orphans the "with" one, thus getting a very brief period of access to the content.