Use of private variables
Solidity supports the private
keyword for declaring private variables and functions. At first, this may look like a place where we can store values privately, but since all the data in Ethereum is public, values stored in these private variables can also be read.
In this recipe, you will learn to read the private values of a contract and ways to prevent such security vulnerabilities.
Getting ready
It's expected that you have a basic understanding of the Ethereum blockchain and solidity before stepping through this recipe.
The Remix IDE (https://remix.ethereum.org) can help you quickly test and deploy the contract. Also, you can use any Ethereum client (geth
, parity
, and so on) and the solc
compiler to run this contract.
How to do it...
- To learn more about reading private variables, consider the following odd-even contract. Each player chooses a number and, if the sum is even, then the first player wins; otherwise, the second player wins:
pragma solidity ^0.4.24; contract...