Replies: 2 comments 10 replies
-
|
Heya! Here is what ERC20 specs say about decimals:
So if the method does not exist, then you simple don't divide by |
Beta Was this translation helpful? Give feedback.
-
|
You should never swallow an error like that. You will almost certainly not do what your users will want. If there is no decimals, it is not a very compliant ERC-20 contract (and may not be an ERC-20) contract at all. In that case I would throw up a big red warning, explaining the situation, and that if they wish to proceed, they need to enter the number of decimals themselves. Keep in mind 0 is a completely valid value for decimals. It just means it is indivisible. Bernie babies are fungible, but are not divisible (at least their value would be drastically impacted). It should never return null; it will throw a CALL_EXCEPTION if the method doesn’t exist. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @zemse @ricmoo
I came up across a very interesting topic.
We have a form, where user can enter
token addressandtoken amount. It's an editable form.Scenario Explained..
token address, we fetchdecimalsand then useethers.utils.formatUnits(amount, decimal).let's say
token addresswas0x....1andamountwas100.18100.18to50.15... When user clicks save, we can't send 50.15 to the contract, so we again fetch thedecimalson the new token address and then doethers.utils.parseUnits("50.15", decimals). Here the problem is that what ifdecimalswas returned 0 or null as it doesn't exist on the newly entered token... Now,parseUnitswill throw an exception and not sure even if I swallow the exception, what I should be sending to the contract ? Maybe i should be sending5015instead of50.15, but It doesn't seem correct to me.I'd appreciate the ideas...
By the way, if
decimalis null, formatUnit by default uses 18 decimals, but here it says that if you don't specify, it's 0 and not 18. https://ethereum.stackexchange.com/a/100073/46200Beta Was this translation helpful? Give feedback.
All reactions