Crowdsale for fixed fiat rate

Hi @abcoathup

Suppose we have ERC20 token and we initially set rate 1 ETH = 300 TKN and suppose 1 ETH = 150 USD. This means 150 USD = 300 TKN or 1 TKN = 0.5 USD. (Assume Token decimals is 18).

Now let’s assume, 2 days later 1 ETH becomes 30 USD, and since we initially set 1 ETH = 300 TKN, 30 USD = 300 TKN, meaning that 1 TKN = 0.1 USD. Lower than before. But my concern is that I want to keep 1TKN constant to some value in USD. For example, 1 TKN = 0.5 USD.

In OZ smart contracts related to crowdsale contract there is no place that takes into account Ether to, say, USD ratio (or any other fiat currency). For example,

     * @dev Returns the rate of tokens per wei at the present time.
     * Note that, as price _increases_ with time, the rate _decreases_.
     * @return The number of tokens a buyer gets per wei at a given time
    function getCurrentRate() public view returns (uint256) {
        if (!isOpen()) {
            return 0;

        // solhint-disable-next-line not-rely-on-time
        uint256 elapsedTime = block.timestamp.sub(openingTime());
        uint256 timeRange = closingTime().sub(openingTime());
        uint256 rateRange = _initialRate.sub(_finalRate);
        return _initialRate.sub(elapsedTime.mul(rateRange).div(timeRange));

In your example example, you assume assume 1 ETH = $200 and derive the rate value. But this calculations are not done in the smart contract itself, the smart contract is sort of “unaware” of Ether to USD ratio.

So, one possible solution that comes to my mind is to design my smart contract so that we could manually adjust any time (every morning or example) ACCORDING TO the ETH-TO-USD ration.
What is your take on this matter? Any best practices, recommendations, suggestions?

1 Like

Hi @bayram,

I don’t have experience with this so not sure of best practices. Hopefully someone in the community can provide some input.

Appropriate (and thorough) testing and auditing would be required with any solution.
You may also need to seek appropriate advice on regulatory considerations.

Options appear to be:

  • Update the rate on a regular basis (e.g. daily)
  • Use an Oracle for USD/Ether and set the rate
  • Accept payment in a stable token rather than Ether
1 Like

Thanks @abcoathup,
Right now we are considering the first option, update the rate on a regular basis (e.g. daily). That’s why I leave the rate in our Crowdsale contract manually adjustable with some upper and lower bounds. I asked about it before in one of my previous posts.

Hopefully someone will share his/her experience.

1 Like

Tagging @itinance in case you have any experience with this that you want to share.

1 Like

I think the easiest answer would be to pull down an oracle feed on-chain regarding what the price of ETH is in USD, and then simply compute the exchange rate each time someone comes to purchase your tokens. This way everyone is getting an accurate rate at the time of purchase and you don’t have to arbitrarily set the price each morning (which might get tedious)

Chainlink has a workable oracle that you would probably be fine using. Their docs have more information you would probably find useful:


Thank you for your feedback.
I guess I’ll need to explore the docs.

1 Like