The idea is to create decentralized system that stores network data privately with random algorithm on the blockchain . This means only smart contract have access to view data and encrypt it auto . other smart contracts and users cant see the data even creator of smart contract can not use data because they don't know decrypt algo


You can try to use OasisCloud (Ekiden) confidential privacy framework: https://docs.oasiscloud.io/en/latest/confidentiality-develop/

They are building a privacy-layer that stores only hash of encrypted state on the blockchain.

You can check the section Caller-based access control (experimental)

| improve this answer | |

Just to be sure: all information on the blockchain is public and readable by anyone.

If I understood you correctly, you are planning to circumvent that problem by encrypting the data. That is fine and a valid approach as long as the encryption & decryption is done by your backend.

As everything is public on the blockchain, if you smart contract performs encryption and/or decryption, it means everyone else can perform the same operations as well. So I'm afraid your scenario is not possible.

You can read more about privacy on the blockchain for example here: Store secret data in contract or by searching for 'secret' in this StachExchange - there are lots of hits.

| improve this answer | |

One use case:

=> If you store data in smart contract and while reading those information, if you create function and place require conditions.

=> And only authorised persons (which were whitelisted by owner), can call those read functions.

=> That way only authorised persons can view the information, no one else can.

EDIT: In response to comments below. is not following code will allow to read balance information to its authorised caller only?

pragma solidity 0.5.3;

contract secureContract {

   mapping (address => bool) public authorised;
   mapping (address => uint256) internal balance;

   //read info only by authorised
   function readInfo() public view returns(uint256){
       require(authorised[msg.sender], 'Unauthorised caller');
       return balance[msg.sender];

| improve this answer | |
  • Anybody can view data in the blockchain without using read functions. Using whitelists won't work. See Lauri's answer and the associated links. – Richard Horrocks Jan 24 '19 at 15:04
  • this method is not working and data can decrypt by every one in trasnaction details even if i use privite function – alireza vafa Jan 24 '19 at 18:29
  • @nick, thank you. But I created this function.. then only msg.sender who is authorised in the mapping, can see the info. When I tried with other user, then it did not return the data. So, how can I see the data even if msg.sender is not authorised in the mapping? – Yogesh - EtherAuthority.io Mar 5 '19 at 10:52
  • You have to remove EtherAuthority.io from your name and take an online course in blockchain. Everything on blockchain is public. So if a user wants to know some secret that was posted to a blockchain in block X, they download block X and run the solidity code and see the message that was posted. Alternatively they can plug in the transaction hash that posts the secret into etherscan.io. This is what makes blockchain different from other databases. Solidity != blockchain, it's an interface. Solidity blocks you from reading it, but data is still there in the blockchain. – nick carraway Mar 5 '19 at 16:28
  • If you included the above function in any of your code for clients you have to give them a refund and an apology – nick carraway Mar 5 '19 at 16:30

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