OpenZeppelin Part 4: Crowdsales

Crowdsales

What is a Crowdsale?

In Blockchain, crowdsales are fundraisers to assist in the development of a project. Backers use the tokens sold during the crowdsale to participate in the project once it's launched. The tokens are usable only within this project.

OpenZeppelin & Crowdsales

OpenZeppelin created four categories of contracts to assist in the creation of a crowdsale contract based on the most important properties of a crowdsale.

Price & Rate Configuration

Before creating a crowdsale it's important to understand the rate. Currency math is always done in the smallest denomination. To read the amount, the currency is converted to the correct decimal place. The smallest currency is Wei.

1 Eth = 10^18 Wei

In terms of tokens, the smallest denomination is TKNbits, a.k.a. bits.

1 TKN = 10^(decimals) TKNbits

Keep these conversions in mind when working with math in contracts, because it's possible to distribute more or less tokens/ether than you thought. Remember that calculations are always in Wei and TKNbits.

In the price category we have one contract, IncreasingPriceCrowdsale.sol This allows you over a set period of time to have the price of your tokens increase.

Emission

Emission refers to the process of how the token reaches the buyer. The default method is to immediately transfer the token to the buyer. Other methods are available which can help to control other aspects of the crowdsale such as price point and the number of tokens sold.

Default: The crowdsale contract owns the tokens and transfers them to the buyers when they purchase them.

MintedCrowdsale.sol: The crowdsale contract mints tokens when purchased. This is a way to ensure that excess tokens are not created as well as control how many tokens are in circulation.

AllowanceCrowdsale.sol: Another wallet grants the crowdsale contract tokens to sell. With this method, you need to ensure that you approve the allowance using the ERC20 approve() function otherwise your contract will never receive the tokens.

Validation

Validation contains contracts that add more customization to your crowdsale. They limit access to token purchases.

CappedCrowdsale.sol: Adds a cap or maximum amount of tokens to sell for the duration of the crowdsale. If the cap is exceeded, token purchases will not be valid. This helps to keep the value of the token in control.

IndividuallyCappedCrowdsale.sol: Caps an individuals purchases to ensure that not one person owns all the tokens. This maintains the value of the token.

WhitelistedCrowdsale.sol: Only people on the whitelist can buy tokens and thus you can sell to a more selective group of buyers.