Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 13th, 2018 84 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. pragma solidity ^0.4.24;
  2.  
  3. import "./IERC20.sol";
  4. import "./SafeMath.sol";
  5.  
  6. contract Crowdsale {
  7.     using SafeMath for uint256;
  8.  
  9.     uint256 private cap; // maximum amount of ether to be raised
  10.     uint256 private weiRaised; // current amount of wei raised
  11.  
  12.     uint256 private rate; // price in wei per smallest unit of token (e.g. 1 wei = 10 smallet unit of a token)
  13.     address private wallet; // wallet to hold the ethers
  14.     IERC20 private token; // address of erc20 tokens
  15.  
  16.    /**
  17.     * Event for token purchase logging
  18.     * @param purchaser who paid for the tokens
  19.     * @param beneficiary who got the tokens
  20.     * @param value weis paid for purchase
  21.     * @param amount amount of tokens purchased
  22.     */
  23.     event TokensPurchased(
  24.         address indexed purchaser,
  25.         address indexed beneficiary,
  26.         uint256 value,
  27.         uint256 amount
  28.     );
  29.  
  30.     // -----------------------------------------
  31.     // Public functions (DO NOT change the interface!)
  32.     // -----------------------------------------
  33.    /**
  34.     * @param _rate Number of token units a buyer gets per wei
  35.     * @dev The rate is the conversion between wei and the smallest and indivisible token unit.
  36.     * @param _wallet Address where collected funds will be forwarded to
  37.     * @param _token Address of the token being sold
  38.     */
  39.     constructor(uint256 _rate, address _wallet, IERC20 _token, uint256 _cap) public {
  40.         // TODO: Your Code Here
  41.         rate = _rate;
  42.         wallet = _wallet;
  43.         token = _token;
  44.         cap = _cap;
  45.        
  46.     }
  47.  
  48.     /**
  49.     * @dev Fallback function for users to send ether directly to contract address
  50.     */
  51.     function() external payable {
  52.         // TODO: Your Code Here
  53.         buyTokens(msg.sender);
  54.     }
  55.  
  56.     function buyTokens(address beneficiary) public payable {
  57.         // Below are some general steps that should be done.
  58.         // You need to decide the right order to do them in.
  59.         //  - Validate any conditions
  60.         //  - Calculate number of tokens
  61.         //  - Update any states
  62.         //  - Transfer tokens and emit event
  63.         //  - Forward funds to wallet
  64.  
  65.         // TODO: Your Code Here
  66.         require(capReached()==false, "Cap Reached");
  67.        
  68.         token.transfer(beneficiary, (msg.value * rate));
  69.        
  70.         weiRaised = weiRaised.add(msg.value);
  71.        
  72.         wallet.transfer(msg.value);
  73.        
  74.         emit TokensPurchased(beneficiary, msg.sender, msg.value, msg.value*rate);
  75.        
  76.     }
  77.  
  78.     /**
  79.     * @dev Checks whether the cap has been reached.
  80.     * @return Whether the cap was reached
  81.     */
  82.     function capReached() public view returns (bool) {
  83.         // TODO: Your Code Here
  84.        bool capper;
  85.         if (cap <= weiRaised) {
  86.           capper =   true;
  87.         }
  88.         else
  89.         {
  90.             capper = false;
  91.         }
  92.        
  93.         return capper;
  94.     }
  95.  
  96.     // -----------------------------------------
  97.     // Internal functions (you can write any other internal helper functions here)
  98.     // -----------------------------------------
  99.  
  100.  
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top