Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPDATED: BuyTokens getting the token amount from a function instead of just multiplication. Useful for making Crowdsales with bonus periods #638

Merged
merged 8 commits into from
Jan 15, 2018
8 changes: 6 additions & 2 deletions contracts/crowdsale/Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ contract Crowdsale {
return new MintableToken();
}


// fallback function can be used to buy tokens
function () external payable {
buyTokens(msg.sender);
}

// Override this method to have a way to add business logic to your crowdsale when buying
function getTokenAmount(uint256 weiAmount) internal view returns(uint256) {
return weiAmount.mul(rate);
}

// low level token purchase function
function buyTokens(address beneficiary) public payable {
require(beneficiary != address(0));
Expand All @@ -73,7 +77,7 @@ contract Crowdsale {
uint256 weiAmount = msg.value;

// calculate token amount to be created
uint256 tokens = weiAmount.mul(rate);
uint256 tokens = getTokenAmount(weiAmount);

// update state
weiRaised = weiRaised.add(weiAmount);
Expand Down