-
Hi, I'm a little confused by the need to multiply by 10^18 in fund(), returning the answer * 10^10 in getPrice() and returning the rate / 10^18 in getConversion() rate. What is going on with all these 0s? I understand this is to use the Wei/Gwei standard, but I can't get my head around exactly why all these values are used.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello @alkali333 |
Beta Was this translation helpful? Give feedback.
-
Thanks for the explanation. So basically, we always put things into 18 decimals. I think it is going to take me a while to familiar with the Wei, Gwei and ETH conversion. It seems rather easy to get the wrong number of 0s which is not ideal when it comes to sending money 🤣Get Outlook for Android
|
Beta Was this translation helpful? Give feedback.
Hello @alkali333
The reason Patrick made the code like this is just for standard reasons, you don't have to it as an obligation and the explanation is the following:
Most of ERC20 Tokens has a standard of 18 decimals, which is based on the WEI, GWEI and ETH conversion. so with that in mind:
uint256 minimumUSD = 50 * 10 ** 18;
is just to fill up the standard.return uint256(answer * 10000000000);
the answer returns a 8 digit value, so the multiplication is again just to get 18.return (ethPrice * ethAmount) / 1000000000000000000
this is because eth price already have all the decimals so you don't want to have 36 decimals, just 18.