Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigNumber issue with the AbiCoder. #418

Closed
nivida opened this issue Feb 8, 2019 · 4 comments
Closed

BigNumber issue with the AbiCoder. #418

nivida opened this issue Feb 8, 2019 · 4 comments
Labels
discussion Questions, feedback and general information.

Comments

@nivida
Copy link

nivida commented Feb 8, 2019

As already discussed here in the Web3.js issue: web3/web3.js#2077 does the new AbiCoder have problems with converting numbers to BigNumbers and encoding them correctly.

Because Web3.js is just passing the value to the ABI coder does this looks like an issue of ethers.js.

@ricmoo Do you have any additional information about this?

@ricmoo
Copy link
Member

ricmoo commented Feb 8, 2019

You cannot use ieee 754 numbers that require more than 53 bits of mantissa. This has been the case in ethers since version 0, years ago. :)

Numbers larger than Number.MAX_SAFE_INTEGER are not tightly packed, so will be imprecise, leading to 50% of the time having dust, 50% being too small.

To solve this, keep in mind to use strings (decimal or 0x prefixed hex) and do all math using big numbers.

Here is some documentation: https://docs.ethers.io/ethers.js/html/notes.html#why-can-t-i-just-use-numbers

10e16 is about the cut off point, since it is 2 ** 53, which is the mantissa limit for 64 bit floating points.

This is a very intentional feature, not a bug. ;)

@ricmoo ricmoo added the discussion Questions, feedback and general information. label Feb 8, 2019
@ricmoo
Copy link
Member

ricmoo commented Feb 9, 2019

Closing this now, but please feel free to add comments and ask questions. Or re-open if you would like to bring more attention to this for other watchers to contribute to. :)

Thanks! :)

@ricmoo ricmoo closed this as completed Feb 9, 2019
@nivida
Copy link
Author

nivida commented Feb 18, 2019

@ricmoo Thanks for the detailed information I will read your documentation 💪

@juventusjude
Copy link

juventusjude commented Apr 12, 2022

@ricmoo.

I have this issue of bigNumber and it only perculiar with ios devices. My code is working smoothly with android, windows except ios. here is the error in iOS devices-->
Error: invalid BigNumber string (argument="value", value="NaN", code=INVALID_ARGUMENT, version=bignumber/5.4.1)
The value is always "NaN. no matter how I did it. I have tried everything all suggestion I read here. all of them are working very smoothly in android and windows . iOS is a big issue. please can you check?

let date = (new Date(date_time)).getTime(); //date_time is a dateString in the form of "2022-04-12 19:00:00"
const matchdate = BigNumber.from(date).div(1000);
console.log("MatchDate",matchdate);
await contract.stakeTeam(fixtureId,team_side,selectedId,localteam_id,visitorteam_id,matchdate,700);

This snippet above is pretty much working in android and windows except iOS.
However, if I replace matchdate with a static number e.g
await contract.stakeTeam(fixtureId,team_side,selectedId,localteam_id,visitorteam_id,1649786400,700); it works perfectly. I am so confused as this is really not happening across all OS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Questions, feedback and general information.
Projects
None yet
Development

No branches or pull requests

3 participants