How to calculate rate for a crowdsale?

Hi @Roodiger

The Crowdsale documentation gives an example of how to calculate the rate:

Using this example for decimals of 5 and an initial rate of $0.01 per whole token:

If you want to issue "1 TKN for every 0.01 dollar (USD) in Ether", we would calculate it as follows:

  • assume 1 ETH == $200
  • therefore, 10^18 wei = $200 or (20,000 cents)
  • therefore, 0.01 USD is 10^18 / 20000 , or 5 * 10^13 wei
  • we have a decimals of 5, so we’ll use 10^5 TKNbits instead of 1 TKN
  • therefore, if the participant sends the crowdsale 5 * 10^13 wei we should give them 10^5 TKNbits
  • therefore the rate is 5 * 10^13 wei === 10^5 TKNbits , or 1 wei = 2*10^-9 TKNbits
  • therefore, our rate is 2*10^-9

Testing this out:

  • If a participant paid 0.01 USD they should get 1 TKN or 10^5 TKNbits
  • 0.01 USD is 5 * 10^13 wei
  • Using the rate of 2*10^-9
  • (5 * 10^13) * (2*10^-9) = 10^5 TKNbits or 1 TKN

Update: The above calculation results in an invalid rate, as 2*10^-9 is not an integer. Need to change to a larger decimals, e.g. 18.

3 Likes