contract WorkingWithVariables {
uint256 public myUint;
function setMyUint(uint _myUint) public {
myUint = _myUint;
}
bool public myBool;
function setMyBool(bool _myBoll) public {
myBool = _myBoll;
}
// Solidity silently wrapping around.
// If myUint8 = 0 and you click on incrementUint() results are 255
uint8 public myUint8;
function incrementUint() public {
myUint++;
}
function decrementUint() public {
myUint--;
}
}
- In Solidity you don’t need a getter function, all function are having a getter function by default.
We can create a special getter function if needed in this way:
contract WorkingWithVariables {
address public myAddress;
function setAddress(address _address) public {
myAddress = _address;
}
function getBalanceOfAddress() public view returns(uint) {
//In Wei
return myAddress.balance;
}
}