Im new to solidity and trying to figure out if there is any way to retrieve a mappings key value for example from the transaction data in which you set it?

mapping (uint => bool) private solution;

function setSolution(uint _number){
    solution[_number] = true;}

Would it be possible for anyone to find the current value of _number in any way while or after I have set it, or is it hidden?

5 Answers 5


Be careful of the answers being given here!

In context of solidity you may not be able to access private mapping from outside the contract BUT

Everything in Ethereum blockchain is PUBLIC

Nodes store copies of entire blockchain and if someone wants they can read your data if its not encrypted. Be sure to write encrypted data if you want true privacy.

Ref 1: Private Info on Ethereum

Ref 2: Storing private data on the ethereum blockchain

  • This is exactly the point of my question, to find out if its posible to read out the data in any way. And if yes, how?
    – Xinorl
    Commented Jul 16, 2018 at 9:24

The answer is simple: you can NOT from any other smart contract. BUT you can without problem using forensic analysis, i.e. “downloading” all or “the relevant” portion of the blockchain and inspecting it with proper tools.

I.e. “private” does not mean “secret” at all, but means “accessible with specific effort only”.

Moreover the transaction you used to set that value is readable without problems using free tools, like etherscan.io services. The transaction is readable directly, listed in your account or in the contract address page.



Just to amplify and clarify, this is an easily-misunderstood issue.

private does not imply, in any way, any assurance of confidentiality whatsoever.

Some further explanation might help.

As you know, Ethereum nodes process every transaction. In order to do that, they need access to the contract state, including the values of private variables. If they didn't "see" that, how would they process transactions that use functions that need it?

There are at least two ways the private information will leak. One way is that an adversary with sufficient knowledge to work at the node/miner software level can rumage around in the blockchain and dig it out. Remember, the data is replicated on everyone's disks, so they have it if they can find it. The other way is to observe inputs, also public, and work out what it must be. So, the word "private" is arguably a bit misleading.

It refers to function "visibility" which is also arguably a bit misleading. In this context, visibility defines what will happen at compile time and what will be in the contract ABI - basically the surface area the contract presents to clients and other contracts.

Would it be possible for anyone to find the current value ...

For emphasis, you can't protect confidential information with private. There are good reasons to use private but they relate to other concerns like catching developer errors and structuring code.

All private state information is discoverable by adversaries.

Hope it helps.


If solution is private then it is available only within the contract.

private: Private functions and state variables are only visible for the contract they are defined in and not in derived contracts.

Solidity Docs # visibility


To get the value of a private mapping you need to access it from getter function within the contract. - That OOP point of view.

In Ethereum, since Everything is public - anyone can read that mapping if they know the contract address and the ABI related to it or may be you can decompile the bytecode stored on that contract address.

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.