SimpleStorage Payable¶
Important
The below exercises will be completed within REMIX. Navigate to: https://remix.ethereum.org
1 Add an acceptEther
function, line 6-8¶
function acceptEther() public payable {
storedData = this.balance;
}
2 Compile and run, test the acceptEther
function¶
- Call the function and send value
- Get the value of
storedData
, was it updated?- Note the value has moved from the EOA to the contract
3 Add a function to withdraw the ether from this contract into the calling account, line 18-20¶
function withdraw() {
msg.sender.transfer(this.balance);
}
4 Add a function to read the balance of the simple storage contract, line 22-24¶
function getMyBalance() returns(uint256) {
return this.balance;
}
Important
Forgetting something? Don’t forget these functions need to be marked view
to return the value.
Go ahead and modify the function with the view
mutability modifer.
5. Add the view
modifier to the getMyBalance
function, line 22¶
function getMyBalance() view returns(uint256) {
return this.balance;
}