-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfundMe1.sol
39 lines (26 loc) · 928 Bytes
/
fundMe1.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
contract fundMe1 {
// mapping store the amount of contributed
mapping (address => uint256) public contributions;
// array store address of contributors
address [] public contributors;
address public owner;
constructor() {
owner = msg.sender;
}
// the main two function in this contract
function contribute() public payable{
//contributions must be greater than 0
require(msg.value>0,"contributions must be greater than 0");
// add address of contributions to mapping
if (contributions[msg.sender]==0){
contributors.push(msg.sender);
}
}
function withdraw() public{
require(msg.sender== owner,"owner can only withdraw this fund");
// withdraw all balance
payable(msg.sender).transfer(address(this).balance);
}
}