-
-
Save MichalZalecki/e5be82e7cbfdcb80b99097d3678a2a97 to your computer and use it in GitHub Desktop.
This file contains 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
pragma solidity 0.4.24; | |
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; | |
import "openzeppelin-solidity/contracts/math/SafeMath.sol"; | |
contract Crowdsale { | |
using SafeMath for uint256; | |
ERC20 public token; | |
address public wallet; | |
uint256 public rate; | |
uint256 public weiRaised; | |
constructor(uint256 _rate, address _wallet, ERC20 _token) public { | |
require(_rate > 0); | |
require(_wallet != address(0)); | |
require(_token != address(0)); | |
rate = _rate; | |
wallet = _wallet; | |
token = _token; | |
} | |
function () external payable { | |
buyTokens(msg.sender); | |
} | |
function buyTokens(address _beneficiary) public payable { | |
require(_beneficiary != address(0)); | |
require(msg.value != 0); | |
uint256 tokens = msg.value.mul(rate); | |
weiRaised = weiRaised.add(msg.value); | |
token.transfer(_beneficiary, tokens); | |
wallet.transfer(msg.value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment