So when I see most Crowdsale contracts the price is set to x ETH and you receive the tokens based on that, if ETH price is down you get more tokens/$ and when ETH price is up, you get less/$. That's just the volatility of crypto. But some tokens are linked to fiat prices directly. $1 gets 1 token so if I send 1 ETH I get however many tokens are determined by the price of ETH.

How is this accomplished?

3 Answers 3


Usually, they lock the price just before starting the crowdsale. They set it to a certain value, and it will stay like that during the entire crowdsale.

It can be something like that :

function startCrowdsale(uint _price) {
    crowdsale_started = true;
    price = _price;
    //more code

Another way, but more costly, is the use of an oracle.

  • But that would set the price in ETH, I am wondering how it is done so that the price in ETH varies but the fiat price stays constant throughout, if that makes sense? What oracle would be used for this kind of thing (I don't know much about oracles)? Thanks for your reply! Apr 27, 2018 at 9:36
  • It doesn't set the price in ETH especially. Let's say the price of 1 ETH is 1000$. The price of 1 token is 2$. If you send 2 ETH, you will receive (2*1000)/2 = 1000 tokens. Apr 27, 2018 at 9:43
  • But if I have hardcoded the price to be $1000 and the ETH price changes, then the price is no longer reflective of the fiat price I wanted to set, right? So it's not really tied to fiat? (Apologies if I am misunderstanding). Apr 27, 2018 at 10:04
  • Yes, but it's not convenient to try to have the correct price all the time, hence they lock it at the start of the crowdsale. Apr 27, 2018 at 10:07
  • Right. I'm asking about crowdsales that link/peg to a fiat price throughout. Thanks anyways! Apr 27, 2018 at 10:12

there is one more way they do it. they calculate the price of ether at the time they receive your payments or they just look the price of ether at the end of ico and all the prices are current value in the market


There used to be several ways to achieve something similar but each method has its inconveniences:

  • Use an oracle to determine exchange price. You need to trust the oracle will not be compromised. It might be expensive to call the oracle in each transaction.
  • Set prices using a bot. You need to trust the team will not manipulate the prices. Prices have to have a threshold so they are updated when it varies above 2% for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.