Is it possible to keep data in a contract, in a similar way that we can create wallet contract? Wondering if it would be possible to keep that and then manage the access to this 'hidden' data according to some other piece of code in the contract.

Higher level here is that I would to implement an mvp for an application where one would, be able to have a guarantee that the user it sends funds to has x or y piece of data in his wallet. Still unsure ethereum is best bet, but inquiring because of the facility of potentially implementing on test network with web3 on nodejs app.

Would appreciate ideas or places to get some more info!

2 Answers 2


It's exceptionally difficult to keep a secret on a platform that's optimized for transparency. There is also the high cost of on-chain storage to think about.

You can explore concepts like zkSnarks, starks and bullet proofs to see if there's a solution. Here, I'll just try to illustrate the nature of the challenge.

Consider that all full nodes including miners must have the complete state in order to evaluate state transitions. That is, they can't run contracts unless they have the data. You can do things like commit/reveal with ease but you'll often run into the problem of revealing the "secret" when you don't want to.

Consider a piggy bank that releases funds upon receipt of a password. We'll hash the password so no one can be sure what the actual password is. This is by no means ready to use. I wanted it to be as simple as possible to illustrate something.

pragma solidity 0.5.1;

contract PiggyBank {

    bytes32 public secretHash;

    constructor(bytes32 hash) public {
        secretHash = hash;

    function deposit() public payable returns(bool) {
        // emit event
        // great! we have money
        return true;

    function withdrawEverything(bytes32 password) public returns(bool) {
        require(keccak256(abi.encodePacked(password)) == secretHash);
        // emit ...
        // great! Someone knew the password
        return true;

So, the secretHash is passed into the constructor and it's open to easy inspection. The fact is, all full nodes have it so public is merely for convenience. If public were removed, it still wouldn't be safe from determined eyes.

That's okay, right? Because knowledge of the secretHash doesn't really help someone work out the password.

Here's the thing

See how withdraw requires the password to work? That means the password will be revealed at the point that function is used. It's "burned". If this were a real piggy bank, one could force a password change as part of the withdrawal process. That is probably not okay for your case.

There is quite a bit of promising research into "zero knowledge proofs" - essentially proving one has information without revealing the information itself. You could concentrate research on available solutions. Depending on the details of what you have in mind, you might find this pattern promising: https://medium.com/@robhitchens/selective-disclosure-with-proof-f6a1ac7be978

It would be possible to reveal that one has a piece of information issued by or checked by a source or group of sources without revealing the information itself. It would also be possible to make payment for the information contingent on providing a piece of information that matches an earlier promise to reveal.


Step 1. I have a satisfactory piece of information that meets all of your criteria. Here is evidence to that effect.

Step 2. Pay into escrow.

Step 3. I have provided the promised information and the buyer is listed as a recipient now. Here is evidence to that effect, so now I am entitled to the funds.

It would not be necessary to expose the data itself to the blockchain and that would provide the assurance that the data isn't exposed in the process. The process would rely heavily on carefully structuring the data to enable selective disclosure.

These are tricky problems.

Hope it helps.


You cannot have hidden data on the Ethereum blockchain. Everything is public and can be seen by anyone else.

As for you MVP, you can certainly write a smart contract wallet that makes varying decisions with incoming ether based on the value of a variable which may or may not be set by the user. That variable, however, will be public for everyone to see.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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