0

I want to emit an event in Solidity that includes a bytes32 field. My frontend will listen for this event, but since events are publicly accessible on-chain, I want to ensure that only my frontend can interpret the data.

Even if someone else sees the event, they should only see an encrypted version of the data.

Is it possible to achieve this within Solidity? If so, what would be the best approach?

3 Answers 3

2

You can do this, but it means the data is encrypted before it's written on the blockchain.

If, for example, you store a password in plain text on the blockchain, encrypting it for an event won't change much, the data is still publicly accessible.

First, you should encrypt the data, then save it on the blockchain, so anyone that doesn't have the encryption key cannot decrypt the data, and you don't have to encrypt it on chain.

1

Public blockchains have public in the name for the reason.

What you are asking cannot be done.

Instead, you need to design your application logic so that there is no private data onchain.

1

Till date it is not possible to encrypt a data on chain through solidity or something.

The only possibility is to encrypt data off chain before submitting it to the transaction, As it is a public chain it display the content as it is to everyone.

So encrypting before submitting the transaction would be the better choice and the only choice available too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.