Created
October 23, 2022 13:26
-
-
Save teerth17/ad32e223bf0912d7062998f074207e8d to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
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.5.0 < 0.9.0; | |
| contract CrowdFunding{ | |
| mapping(address=>uint) public contributors; | |
| address public manager; | |
| uint public minimumContribution; | |
| uint public deadline; | |
| uint public target; | |
| uint public raisedAmount; | |
| uint public noOfContributors; | |
| constructor(uint _target,uint _deadline){ | |
| target = _target; | |
| deadline = block.timestamp + _deadline; | |
| minimumContribution = 100 wei; | |
| manager = msg.sender; | |
| } | |
| struct Request{ | |
| string description; | |
| address payable recipient; | |
| uint value; | |
| bool completed; | |
| uint noOfVoters; | |
| mapping(address=>bool) voters; | |
| } | |
| mapping(uint=>Request) public requests; | |
| uint public numRequests; | |
| function sendWei() public payable{ | |
| require(block.timestamp < deadline,"Deadline has been passed"); | |
| require(msg.value >= minimumContribution,"Minimum Contibution has not met"); | |
| if(contributors[msg.sender] == 0){ | |
| noOfContributors++; | |
| } | |
| contributors[msg.sender]+=msg.value; | |
| raisedAmount+=msg.value; | |
| } | |
| function getContractBalance() public view returns(uint){ | |
| require(msg.sender==manager); | |
| return address(this).balance; | |
| } | |
| function refund() public{ | |
| require(block.timestamp>deadline && raisedAmount<target,"You are not eligible for refund"); | |
| require(contributors[msg.sender]>0); | |
| address payable user = payable(msg.sender); | |
| user.transfer(contributors[msg.sender]); | |
| } | |
| function sendRequest(string memory _description,address payable _recipient,uint _value) public{ | |
| require(msg.sender==manager,"Only Manager Can Call THis Function"); | |
| Request storage newRequest = requests[numRequests]; | |
| numRequests++; | |
| newRequest.description = _description; | |
| newRequest.recipient = _recipient; | |
| newRequest.value = _value; | |
| newRequest.completed = false; | |
| newRequest.noOfVoters = 0; | |
| } | |
| function voteRequest(uint _requestNo) public{ | |
| require(contributors[msg.sender] > 0,"You must be a Contributor"); | |
| Request storage thisRequest = requests[_requestNo]; | |
| require(thisRequest.voters[msg.sender] == false,"You have Voted Once"); | |
| thisRequest.voters[msg.sender] = true; | |
| thisRequest.noOfVoters++; | |
| } | |
| function makePayment(uint _requestNo) public{ | |
| require(msg.sender==manager); | |
| require(raisedAmount>=target); | |
| Request storage thisRequest= requests[_requestNo]; | |
| require(thisRequest.completed == false,"The request has been completed"); | |
| require(thisRequest.noOfVoters > noOfContributors/2,"You loose on Voting"); | |
| thisRequest.recipient.transfer(thisRequest.value); | |
| thisRequest.completed=true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment