Loading...
Anyone will be able to list his/her project for crowdfunding in smart contract.
Create a function where each project will have unique Id. You can ask for some details like project description, require funds, deadline, etc while registering for particular project for crowdfunding. After registering for crowdfunding the contract Manager
pragma solidity ^0.7.0;
contract crowdFunding{
mapping (address => uint) public fundContributors;
address public manager;
uint public deadline;
uint public targetAmount;
uint public raisedAmount;
struct Request {
string description;
address payable reciepient;
uint value;
bool completed;
}
mapping (uint => Request) public requests;
uint public numRequests;
constructor (uint _targetAmount, uint _deadline) {
targetAmount = _targetAmount;
deadline = block.timestamp + _deadline;
manager = msg.sender;
}
function sendFunds() public payable {
require(block.timestamp < deadline, "crowdFunding is over");
fundContributors[msg.sender] += msg.value;
raisedAmount += msg.value;
}
function getBalance() public view returns(uint){
return address(this).balance;
}
function refund() public {
require(block.timestamp > deadline && raisedAmount < targetAmount, "You are not eligible for refund");
require(fundContributors[msg.sender] > 0);
address payable user = payable(msg.sender);
user.transfer(fundContributors[msg.sender]);
fundContributors[msg.sender] = 0;
}
modifier onlyManager() {
require(msg.sender == manager, "Only manager can call this function");
_;
}
function createRequest (string memory _description, address payable _reciepient, uint _value) public onlyManager {
Request storage newRequest = requests[numRequests];
numRequests++;
newRequest.description = _description;
newRequest.reciepient = _reciepient;
newRequest.value = _value;
newRequest.completed = false;
}
function makePayment (uint _requestNo) public onlyManager{
require (raisedAmount >= targetAmount);
Request storage thisRequest = requests[_requestNo];
require(thisRequest.completed == false , "This request has been completed");
thisRequest.reciepient.transfer(thisRequest.value);
thisRequest.completed = true;
}
}
will verify the details and validate it. Once owner has validated for the project, it is available for public to fund the project.