Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *Submitted for verification at Etherscan.io on 2019-09-19
- */
- pragma solidity ^0.5.11;
- contract CrowdSale{
- mapping (address=> uint256) public contributions;
- uint256 public totalRaised;
- uint256 public maxAmount;
- uint256 public saleEndTimeStamp;
- bool public saleActive;
- address public admin;
- // constructor to enable basic parameters of the crowdsale
- constructor(uint256 _maxAmount, bool _saleActive, uint256 _saleEndTimeStamp) public {
- admin = msg.sender;
- // Max amount limit
- maxAmount = _maxAmount;
- // Sale status on launch
- saleActive = _saleActive;
- // Sale end time
- saleEndTimeStamp = _saleEndTimeStamp;
- }
- // Function to deposit ETH for the crowdsale
- function contribute() public payable returns (bool){
- require(msg.value > 0, "Deposit ETH along with the function");
- require(msg.value + totalRaised < maxAmount, "Crowdsale limit reached");
- require(saleActive, "Sale hasn't started or has ended");
- require(now < saleEndTimeStamp, "Sale has ended");
- contributions[msg.sender] = msg.value;
- totalRaised = totalRaised + msg.value;
- return true;
- }
- // Function to end crowdsale and distribute funds to admin
- function endCrowdSale() public {
- require(msg.sender == admin, "Only admin can end the sale");
- saleActive = false;
- msg.sender.transfer(totalRaised);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement