-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSimpleWallet.sol
More file actions
32 lines (27 loc) · 1.32 KB
/
SimpleWallet.sol
File metadata and controls
32 lines (27 loc) · 1.32 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
// This is a smart contract - a program that can be deployed to the Ethereum blockchain.
contract SimpleWallet {
// An 'address' is comparable to an email address - it's used to identify an account on Ethereum.
address payable private owner;
// Events allow for logging of activity on the blockchain.
// Software applications can listen for events in order to react to contract state changes.
event LogDeposit(uint amount, address indexed sender);
event LogWithdrawal(uint amount, address indexed recipient);
// When this contract is deployed, set the deploying address as the owner of the contract.
constructor() {
owner = payable(msg.sender);
}
// Send ETH from the function caller to the SimpleWallet contract
function deposit() public payable {
require(msg.value > 0, "Must send ETH.");
emit LogDeposit(msg.value, msg.sender);
}
// Send ETH from the SimpleWallet contract to a chosen recipient
function withdraw(uint amount, address payable recipient) public {
require(msg.sender == owner, "Only the owner of this wallet can withdraw.");
require(address(this).balance >= amount, "Not enough funds.");
emit LogWithdrawal(amount, recipient);
recipient.transfer(amount);
}
}