|This page is incomplete. We’re working to improve it for the next release. Stay tuned!|
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 conforms the base architecture for crowdsales. It is 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.
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.
fallback function DO NOT OVERRIDE Note that other contracts will transfer funds with a base gas stipend of 2300, which is not enough to call buyTokens. Consider calling buyTokens directly when purchasing tokens from a contract.
low level token purchase DO NOT OVERRIDE
This function has a non-reentrancy guard, so it shouldn’t be called by
Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
super in contracts that inherit from Crowdsale to extend their validations.
Example from CappedCrowdsale.sol’s _preValidatePurchase method:
require(weiRaised().add(weiAmount) ⇐ cap);
Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met.
Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.
Executed when a purchase has been validated and is ready to be executed. Doesn’t necessarily emit/send tokens.
Override for extensions that require an internal state to check for validity (current user contributions, etc.)
Override to extend the way in which ether is converted to tokens.
Extension of Crowdsale where tokens are held by a wallet, which approves an allowance to the crowdsale.
Extension of Crowdsale contract whose tokens are minted in each purchase. Token ownership should be transferred to MintedCrowdsale for minting.
Crowdsale with a limit for total contributions.
Crowdsale with per-beneficiary caps.
Returns the amount contributed so far by a specific beneficiary.
Extend parent behavior requiring purchase to respect the beneficiary’s funding cap.
Extension of Crowdsale contract where purchases can be paused and unpaused by the pauser role.
Crowdsale accepting contributions only within a time frame.
Constructor, takes crowdsale opening and closing times.
Extend parent behavior requiring to be within contributing period.
Crowdsale in which only whitelisted users can contribute.
Extension of TimedCrowdsale with a one-off finalization action, where one can do extra work after finishing.
Must be called after crowdsale ends, to do some extra finalization work. Calls the contract’s finalization function.
Can be overridden to add finalization logic. The overriding function should call super._finalization() to ensure the chain of finalization is executed entirely.
Crowdsale that locks tokens from withdrawal until it ends.
Overrides parent by storing due balances, and delivering tokens to the vault instead of the end user. This
ensures that the tokens will be available by the time they are withdrawn (which may not be the case if
_deliverTokens was called later).
FinalizableCrowdsale contract that adds a funding goal, and the possibility of users
getting a refund if goal is not met.
RefundablePostDeliveryCrowdsale instead. Note that if you allow tokens to be traded before the goal
is met, then an attack is possible in which the attacker purchases tokens from the crowdsale and when they sees that
the goal is unlikely to be met, they sell their tokens (possibly at a discount). The attacker will be refunded when
the crowdsale is finalized, and the users that purchased from them will be left with worthless tokens.
Investors can claim refunds here if crowdsale is unsuccessful.
Extension of RefundableCrowdsale contract that only delivers the tokens once the crowdsale has closed and the goal met, preventing refunds to be issued to token holders.