Created
July 9, 2022 20:12
-
-
Save mikhail-chystsiakou/62db6c0d432fa1292c8392a3d1e134e7 to your computer and use it in GitHub Desktop.
solidity homework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifer: MIT | |
pragma solidity ^0.8.0; | |
contract PiggyWallet { | |
address payable private owner; | |
mapping (address => uint256) private wallet; | |
function putMoney() public payable { | |
wallet[msg.sender] += msg.value; | |
} | |
function withdrawMoney(uint256 amount) public { | |
if (wallet[msg.sender] < amount) { | |
revert('Not enough money'); | |
} | |
wallet[msg.sender] -= amount; | |
payable(msg.sender).transfer(amount); | |
} | |
function showMoney() public view returns(uint256) { | |
return wallet[msg.sender]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment