Crowdsale
contract Crowdsale
Crowdsale is a base contract for managing a token crowdsale, allowing investors to purchase tokens with ether. This contract implements such functionality in its most fundamental form and can be extended to provide additional functionality and/or custom behavior. The external interface represents the basic interface for purchasing tokens, and conform the base architecture for crowdsales. They are *not* intended to be modified / overridden. The internal interface conforms the extensible and modifiable surface of crowdsales. Override the methods to add functionality. Consider using 'super' where appropriate to concatenate behavior.
Index
Reference
Events
TokensPurchased
event TokensPurchased(address purchaser, address beneficiary, uint256 value, uint256 amount)
Event for token purchase logging.
- Parameters:
purchaser
- who paid for the tokensbeneficiary
- who got the tokensvalue
- weis paid for purchaseamount
- amount of tokens purchased
Functions
_deliverTokens
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal
Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.
- Parameters:
beneficiary
- Address performing the token purchasetokenAmount
- Number of tokens to be emitted
_forwardFunds
function _forwardFunds() internal
Determines how ETH is stored/forwarded on purchases.
_getTokenAmount
function _getTokenAmount(uint256 weiAmount) internal view returns (uint256)
Override to extend the way in which ether is converted to tokens.
- Parameters:
weiAmount
- Value in wei to be converted into tokens- Returns:
- Number of tokens that can be purchased with the specified _weiAmount
_postValidatePurchase
function _postValidatePurchase(address beneficiary, uint256 weiAmount) internal view
Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met.
- Parameters:
beneficiary
- Address performing the token purchaseweiAmount
- Value in wei involved in the purchase
_preValidatePurchase
function _preValidatePurchase(address beneficiary, uint256 weiAmount) internal view
Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use `super` in contracts that inherit from Crowdsale to extend their validations. Example from CappedCrowdsale.sol's _preValidatePurchase method: super._preValidatePurchase(beneficiary, weiAmount); require(weiRaised().add(weiAmount) <= cap);.
- Parameters:
beneficiary
- Address performing the token purchaseweiAmount
- Value in wei involved in the purchase
_processPurchase
function _processPurchase(address beneficiary, uint256 tokenAmount) internal
Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send tokens.
- Parameters:
beneficiary
- Address receiving the tokenstokenAmount
- Number of tokens to be purchased
_updatePurchasingState
function _updatePurchasingState(address beneficiary, uint256 weiAmount) internal
Override for extensions that require an internal state to check for validity (current user contributions, etc.).
- Parameters:
beneficiary
- Address receiving the tokensweiAmount
- Value in wei involved in the purchase
buyTokens
function buyTokens(address beneficiary) public payable
Low level token purchase ***DO NOT OVERRIDE*** This function has a non-reentrancy guard, so it shouldn't be called by another `nonReentrant` function.
- Modifiers:
- nonReentrant
- Parameters:
beneficiary
- Recipient of the token purchase
fallback
function () external payable
Fallback function ***DO NOT OVERRIDE*** Note that other contracts will transfer fund with a base gas stipend of 2300, which is not enough to call buyTokens. Consider calling buyTokens directly when purchasing tokens from a contract.
fallback
function (uint256 rate, address wallet, IERC20 token) public
The rate is the conversion between wei and the smallest and indivisible token unit. So, if you are using a rate of 1 with a ERC20Detailed token with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
- Parameters:
rate
- Number of token units a buyer gets per weiwallet
- Address where collected funds will be forwarded totoken
- Address of the token being sold
rate
function rate() public view returns (uint256)
- Returns:
- the number of token units a buyer gets per wei.
token
function token() public view returns (IERC20)
- Returns:
- the token being sold.
wallet
function wallet() public view returns (address)
- Returns:
- the address where funds are collected.
weiRaised
function weiRaised() public view returns (uint256)
- Returns:
- the amount of wei raised.