-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfundMe2.sol
38 lines (29 loc) · 1.02 KB
/
fundMe2.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 fundMe2{
// address of the owner of the contract
address public owner;
// total amount of fund raised
uint256 public totalFund;
// mapping to store contributions amount of address
mapping(address=> uint256) public contributions;
// constructor to set owner
constructor() {
owner=msg.sender;
}
// function to allow user to contribute
function contribute() public payable{
require(msg.value>0,"contributions must be greater than 0");
contributions[msg.sender]+= msg.value;
totalFund+=msg.value;
}
//function to withdraw fund by the owner
function withdraw() public payable onlyOwner{
payable(owner).transfer(address(this).balance);
}
// Modifier to restrict functions to the owner
modifier onlyOwner() {
require(msg.sender == owner, "Only owner can withdraw funds");
_; // This line allows the function code to run after the modifier check.
}
}