Skip to content

Instantly share code, notes, and snippets.

@ac12644
Last active August 14, 2022 09:53
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 ac12644/2e2c7d6611662c9746e1acfd36be39fd to your computer and use it in GitHub Desktop.
Save ac12644/2e2c7d6611662c9746e1acfd36be39fd to your computer and use it in GitHub Desktop.
function buyTokens(address _investor) public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_investor, weiAmount);
// update state
weiRaised = weiRaised.add(weiAmount);
// Calculate the token amount
uint256 tokens = _calculateToken(weiAmount);
// Transfer them to the investor address
_processPurchase(_investor, tokens);
}
function _deliverTokens(address _investor, uint256 _tokenAmount) internal {
token.transfer(_investor, _tokenAmount);
}
function _processPurchase(address _investor, uint256 _tokenAmount)
internal
{
_deliverTokens(_investor, _tokenAmount);
}
function _calculateToken(uint256 _weiAmount)
internal
view
returns (uint256)
{
return _weiAmount.mul(rate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment