I have a secret message that I want to share it with a specific Ethereum Address using a smart contract and I want no one else to see it except that specific Ethereum address user. Is it possible?

  • If I share it via event everyone would see it.
  • If I set a variable and code a getter for that, also everyone could access it.

[Q] I know that everything is public on the blockchain, but somehow is it possible to keep a string private for the specific user and only that specific user can view it?


1 Answer 1


As you stated, everything is public, thus there is not much to "hide". You may add as many heuristics as you want, anyone persistent enough will be able to decode it.

Any encoding should be done before hand (think: server-side as opposed to client-side).

However, supposing you already know the reader address, one solution is to use byte-wise XOR operation on the secret message with the reader address.

Think of it as using a symmetric encryption with msg.sender as a key. Your function will be:

string your_secret_value

function setSecret(string s) public {
             your_secret_value = s;

function getSecret() public constant returns (string s) {
             return XOR(msg.sender, your_secret_value);


Then, you compute locally d = XOR( 0xALLOWED_ADDRESS, your_message ), and call setSecret(d). This will allow only one specific address to see a message that is not junk.

  • Why did you deleted and re-write your answer again. @Betcheg
    – alper
    Mar 16, 2018 at 14:02
  • Because this method is a valid way of encoding with a non-public key. I don't think you understand it. In my previous post, every one in the comment was focused on telling me the first method was not safe even though i stated it in the message.
    – Betcheg
    Mar 16, 2018 at 14:05
  • This is not safe, all Ethereum addresses are public and by knowing those everyone can obtain the secret message via XOR. @Betcheg
    – alper
    Mar 16, 2018 at 14:11
  • Do you intend to publish the allowed address? If not, how could anyone guess it in the first place ??
    – Betcheg
    Mar 16, 2018 at 14:13
  • In my case its intended. The addresses are logged on the event. @Betcheg
    – alper
    Mar 16, 2018 at 14:16

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