I’m also having some trouble understanding how to calculate rate. The target decimals is 5 not 18, and I want the initial rate to be $.01 per token. I’m not sure how to calculate this for my rate variable for the 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
, or5 * 10^13 wei
- we have a decimals of 5, so we’ll use
10^5 TKNbits
instead of1 TKN
- therefore, if the participant sends the crowdsale
5 * 10^13 wei
we should give them10^5 TKNbits
- therefore the rate is
5 * 10^13 wei === 10^5 TKNbits
, or1 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
or10^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.
Hi @Roodiger Did the explanation of rate calculation make sense?
If it answered your question can you mark my reply as the solution. Thanks
A post was split to a new topic: Token sale for fixed fiat rate
A post was split to a new topic: What is the argument you enter into the constructor for the crowdsale rate?
for future, I made a Crowdsale rate Calculator on https://ico-calculator.steaksoft.net/
feel free to use anytime