Skip to content

Instantly share code, notes, and snippets.

@MichalZalecki MichalZalecki/Crowdsale.sol Secret
Last active Jul 3, 2018

What would you like to do?
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 {
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.