0
  function _getTokenAmount(uint weiAmount) internal override view returns(uint256) {
      super._getTokenAmount(weiAmount);
      int currentPrice = priceFeed.getLatestPrice();
      uint weiToEightDec = weiAmount / (10 * 10 ** 10);
      uint exchangeRatePerWei = 1000000000000000000 / uint(currentPrice)  ;
      uint usdAmount = weiToEightDec* exchangeRatePerWei;
      uint amountToGive = usdAmount * 25;
      return(amountToGive);
  }

The decimals are throwing me off. I want to get the exchange rate of 1 ETH to USD first, then get the exchange rate from that. Using the exchange rate, I will multiply it by the amount of ETH given to calculate the dollar amount, then use that to give the correct amount of tokens ($1 @ 0.04 = 25 per dollar).

What am I doing wrong here?

LMan
  • 13
  • 3
  • Can you give an example value of the `currentPrice` and what it represents? Price of ETH in USD, including some amout of decimals, ...? – Petr Hejda Oct 21 '21 at 09:33
  • Sure, it is the price of 1 ETH in USD with 8 decimals, from Chainlink's Oracle feed. – LMan Oct 22 '21 at 01:52

0 Answers0