The question was, what advantage has using a different decimals than 18. The only one that came to my mind was having a more scarce token, since when you can only send full tokens, when for example having no decimals, the token automatically is more scarce. And metamask converts to decimals, it has no problems working with different decimals from what I know.

Feb 24, 2021, 9:36 AM
Metamask has no issues converting, but the dev sometimes might have issues working with different decimals. You always have to make provision for a different decimal as against 18 decimals that most tools already are set to by default
Yeah mate. Here now
Feb 24, 2021, 11:49 AM
As I said, I wrote that only due to that being the only advantage I know. I wrote that it's otherwise bad to do so :)
Feb 24, 2021, 11:49 AM
From the code you just shared. I see you are actually transferring the same thing out. Not a fraction. Diving msg.value by 1e18 is just like dividing it myself. So its same value that gets out.
Feb 24, 2021, 11:51 AM
msg.value is already in WEI, so if he does divide it by 1e18, he in fact in the end forwards only 1 WEI while the rest (0.99999...) stays in the contract.
1 ETH = 1000000000000000000 WEI
1000000000000000000 / 1000000000000000000 = 1
So only 1 WEi will be forwarded.
Feb 24, 2021, 11:54 AM
True. Very true.
@cryptokk so msg.value is actually taken out first before even sending in actual calculated amount in the contract.
Feb 24, 2021, 12:01 PM
What you have to keep in mind is this:
Solidity/Ethereum have no decimals, meaning, 0.0001 ether for example would be impossible to send.
To solve that problem, they implemented the decimals variable. So instead of 1 ether, you own 1*1e18 = 1000000000000000000 WEI. That represents one ether.
To go back to our example, you would not have 0.0001 ether, but 100000000000000 WEI in the smart contract.
When working with msg.value, msg.value is always the WEI representation of the value sent. So 1.1 ETHER would mean msg,value is 1.1 * 1e18 = 1100000000000000000 WEI.
You're welcome!
Feb 24, 2021, 12:07 PM
Well said. This explains the reason for decimals. You do know your onions @cryptokk
Feb 24, 2021, 12:07 PM
Thanks alot :)
Feb 24, 2021, 12:08 PM
Yeah, I like the way you break it down. Atleast @kalki_a can relate better
Feb 24, 2021, 12:09 PM
Cmon. Noone will join when you write like that.
oops
Feb 24, 2021, 12:13 PM

© 2024 Draquery.com All rights reserved.