Skip to content

Instantly share code, notes, and snippets.

@MichalZalecki
Last active July 3, 2018 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichalZalecki/e5be82e7cbfdcb80b99097d3678a2a97 to your computer and use it in GitHub Desktop.
Save MichalZalecki/e5be82e7cbfdcb80b99097d3678a2a97 to your computer and use it in GitHub Desktop.
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