3
contract {
  mapping (bytes32 => uint256) private balances;

  function setValue(uint256 a) {
    uint index = sha3(msg.sender);
    balances[index] = a;
  }
}
  1. I put a "private" before balances , Can I see the storage data by anylize the blockchain data ?
  2. If i call "setValue()" twice with different param, ex. first time, contractInstance.setValue(param1), the second time, contractInstance.setValue(param2), can i read the "param1" data from blockchain data now ?

https://live.ether.camp/account/Af30D2a7E90d7DC361c8C4585e9BB7D2F6f15bc7 this website can see some contract datas, some ? or everything ? Thank you!

migrated from ethereum.meta.stackexchange.com Apr 13 '17 at 18:19

This question came from our discussion, support, and feature requests site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain.

1

Blockchain stores every transactions in blocks. Every method that write/stores something on a contract, generates a transaction.

What it means to you: When you run contractInstance.setValue("param1"), it will generate a transaction (with address X) calling setValue, with parameter value "param". That, itself, is visible for anyone that has access to the block. Just find the block with address X (the original transaction) and the data will be there.

If you want to obscure the information, you can always encrypt on input/output or store a hash to the information stored somewhere else.

  • Thank you, i know the param1 will saved in blockchain associate with balances variable, if "balances[sha3(msg.sender)] = 100", and i update it by calling contractInstance.setValue(200) , when all the transaction execute, all data wrote in blockchain, This time can i find the value 100 record ? or replaced by value 200 ? – wakerch Apr 14 '17 at 2:01
  • Look, at the first transaction, that will write 100 on the parameter, you will always find the value 100. In a second transaction (that will write 200), you will always find the 200 value. Each transaction is written to blockchain and will last there 'forever' ... even if the contract state changes, the transactions that altered the contract will be always there. With their values. – Eduardo Elias Saléh Apr 17 '17 at 16:12
  • Thank you, i read the yellow paper, it say the contract state saved in a underlying database , and how can i access it ? – wakerch Apr 18 '17 at 14:55
  • My question is: to read value of one variable. Client will go through whole blockchain for reading and collecting right ? – hqt Mar 10 '18 at 16:24
  • @hqt not really. When reading one variable, your client will go on its version stored within your local node, retrieves the bytecode and reads its state from there, only. – Eduardo Elias Saléh Mar 12 '18 at 10:42
1

The use of the private keyword is to scope a variable or function to only be readable to the contract it is declared in. It is not visible to other contracts or inherited by a deriving contract.

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

It has no intention of keeping data set to the blockchain 'private' as all data is visible or discoverable in one way or another.

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.