Convert Crowdsales rate into price in WEI/ETH

Hey everyone! So, I recently wrote a crowd-sale using OpenZeppelin. Right now, I am wondering how do I get token’s “price” in WEI or ETH ? do we have any example for that or something like that?

1 Like

Hi @PradhumnaPancholi,

I haven’t come across a Crowdsale price, but you should be able to calculate it using the rate.

Yeah, I am aware that there is no price in Crowdsale. I am just looking for ways to calculate it. If my token has standard 18 decimal, I think it should be as simple as “rate * 10^18”. Just looking for examples to verify that and test it myself in my code.

1 Like

Hi @PradhumnaPancholi,

The formula is: TKNbits = rate * wei (From: https://docs.openzeppelin.com/contracts/2.x/crowdsales#crowdsale-rate)

Which should then be:

  • The price for 1 TKNbit is wei = 1 / rate
  • the price for 1 TKN with 18 decimals is wei = (1 * 10^18) / rate

Depending on the value for rate you will have to watch out for rounding.

Though I recommend writing appropriate tests to check this.

1 Like