Crowdsale test returns SafeMath Multiplication Overflow

Hi @Roodiger

The issue is the rate.

Apologies, when I did the rate calculation (How to calculate rate for a crowdsale?) I didn’t pick up the implication of the value of rate. const rate = new BN(2*10^-9);
2*10^-9 is less than one and is not an integer so is not a valid value to use.

If instead of decimals 5 you used decimals 18 then a valid rate can be calculated.

Using decimals of 18 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 18, so we’ll use 10^18 TKNbits instead of 1 TKN
  • therefore, if the participant sends the crowdsale 5 * 10^13 wei we should give them 10^18 TKNbits
  • therefore the rate is 5 * 10^13 wei === 10^18 TKNbits , or 1 wei = 2*10^4 TKNbits
  • therefore, our rate is 2*10^4

Testing this out:

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