Created
February 24, 2022 16:30
-
-
Save kudchikarsk/6e68dd37842021266293d6aee7bad354 to your computer and use it in GitHub Desktop.
CrowdFunding Dapp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
contract CrowdFunding { | |
uint public minContribution; | |
uint public deadline; | |
uint public target; | |
uint public raiseAmount; | |
uint public noOfContributors; | |
mapping(address => uint) public contributors; | |
constructor(uint _target, uint _expireAfter) { | |
minContribution = 100 wei; | |
target = _target; | |
deadline = block.timestamp + _expireAfter; | |
} | |
function sendEth () payable public { | |
require(msg.value > minContribution, "Minimum contributon not met."); | |
require(block.timestamp < deadline, "Deadline has been passed."); | |
if(contributors[msg.sender] == 0) { | |
noOfContributors++; | |
} | |
contributors[msg.sender] += msg.value; | |
raiseAmount += msg.value; | |
} | |
function refund() public { | |
require(block.timestamp > deadline); | |
require(contributors[msg.sender] > 0); | |
address payable user = payable(msg.sender); | |
uint value = contributors[msg.sender]; | |
user.transfer(value); | |
contributors[msg.sender] = 0; | |
raiseAmount -= value; | |
noOfContributors--; | |
} | |
function getBalance() public view returns(uint) { | |
return address(this).balance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment