-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEtherWallet.sol
More file actions
53 lines (33 loc) · 1.27 KB
/
Copy pathEtherWallet.sol
File metadata and controls
53 lines (33 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
contract SimpleCustomWallet {
event moneyDeposited(address indexed sender ,uint amount );
event moneyWithdrawn(address indexed sender ,uint amount );
address payable owner;
uint private constant amountToSend = 3 ether;
mapping(address => bool) hasAddressPaid;
constructor(address payable _owner){
owner = _owner;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
receive() external payable {
sendMoneyToContract();
}
function sendMoneyToContract () payable public {
require(msg.sender != address(this), "Sender cannot be the smart contract");
require(msg.value >= amountToSend, "Amount to send is 0.1 ether");
hasAddressPaid[msg.sender] = true;
emit moneyDeposited(msg.sender, msg.value);
}
function withdrawFromContract () payable onlyOwner public {
uint balanceOfContract = address(this).balance;
(bool success,)= msg.sender.call{value: balanceOfContract}("");
require(success, "Failed TXN");
emit moneyWithdrawn(msg.sender, msg.value);
}
}
// make the contract accept eth
// only owner can withdraw