Skip to content

Instantly share code, notes, and snippets.

@mikhail-chystsiakou
Created July 9, 2022 20:12
Show Gist options
  • Save mikhail-chystsiakou/62db6c0d432fa1292c8392a3d1e134e7 to your computer and use it in GitHub Desktop.
Save mikhail-chystsiakou/62db6c0d432fa1292c8392a3d1e134e7 to your computer and use it in GitHub Desktop.
solidity homework
// 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