Advertisement
Guest User

simplified-crowdsale

a guest
Oct 17th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. /**
  2. *Submitted for verification at Etherscan.io on 2019-09-19
  3. */
  4.  
  5. pragma solidity ^0.5.11;
  6. contract CrowdSale{
  7.  
  8. mapping (address=> uint256) public contributions;
  9. uint256 public totalRaised;
  10. uint256 public maxAmount;
  11. uint256 public saleEndTimeStamp;
  12. bool public saleActive;
  13. address public admin;
  14.  
  15. // constructor to enable basic parameters of the crowdsale
  16. constructor(uint256 _maxAmount, bool _saleActive, uint256 _saleEndTimeStamp) public {
  17. admin = msg.sender;
  18. // Max amount limit
  19. maxAmount = _maxAmount;
  20. // Sale status on launch
  21. saleActive = _saleActive;
  22. // Sale end time
  23. saleEndTimeStamp = _saleEndTimeStamp;
  24. }
  25.  
  26. // Function to deposit ETH for the crowdsale
  27. function contribute() public payable returns (bool){
  28. require(msg.value > 0, "Deposit ETH along with the function");
  29. require(msg.value + totalRaised < maxAmount, "Crowdsale limit reached");
  30. require(saleActive, "Sale hasn't started or has ended");
  31. require(now < saleEndTimeStamp, "Sale has ended");
  32. contributions[msg.sender] = msg.value;
  33. totalRaised = totalRaised + msg.value;
  34. return true;
  35. }
  36.  
  37.  
  38. // Function to end crowdsale and distribute funds to admin
  39. function endCrowdSale() public {
  40. require(msg.sender == admin, "Only admin can end the sale");
  41. saleActive = false;
  42. msg.sender.transfer(totalRaised);
  43. }
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement