3

I'm quite new in Ethereum world and I'm still little bit confused about this: If I store any data on blockchain, is it readable from anyone? Let's say I have this is Solidity:

...
string private myVerySecretText;

function getText() external returns(string){
 require(msg.sender == something);
 return myVerySecretText;
}
...

If I'm the user that match the require statement, I can access the data, but is there some possiblity to read this data from anyone else? I know that the whole blockchain is public, so is there possible to read somehow even the private data? And can anyone read the code from my smartcontract when is deployed on a blockchain?

5

All the data in the Blockchain is public. The "public" keyword creates a getter for the variable, (a function that return the value). When you make it private the getter is not created but you can access the storage of the contract. web3 allows you to read the storage using:

web3.getStorageAt(address, position)

see this for more info

Hope this helps

  • Thank you. And are the data readable after the getStorageAt function or is it in some format/ data type that is not readable and can't be transferred to a readable form? I'm asking because I want to store there some private data and I'm not sure if is necessary to use some encryption or I can just let it be only as it is.. – Banana Cake Jan 6 at 21:41
  • 1
    web3 will return a number in hexadecimal. If the information is private you should encrypt it. If this answered your question please accept the answer. – Jaime Jan 6 at 22:28
  • Thank you. One more question - are the data passed into a smart contract function in transaction visable? Let's say I want to call function SetSecretText(string newText) external ... (inside the function is some encryption). Is the value of newText parameter in a transaction visable also publicly? – Banana Cake Jan 7 at 18:14
  • 1
    yes, it is visible so the encryption should be done offline such that the data that you send is already encrypted. – Jaime Jan 7 at 19:58
  • 1
    yes, every transaction that has happened in the network is visible. – Jaime Jan 7 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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