node-metamask icon indicating copy to clipboard operation
node-metamask copied to clipboard

When dealing with very large numbers (>= 1e+21), `result` in the `send()` method fails to convert scientific notation to a number, creating downstream BigNumber conversion errors

Open nicholaspai opened this issue 5 years ago • 1 comments

Description

First of all, thank you for building this package in the first place, it is really awesome! 💯

I ran into this error when using the MetaMask provider and calling web3.eth.getBalanceOf(address) on an account with a lot of ETH. I seed all of my GanacheCLI accounts with 10,000 ETH so I ran into this error easily. I encountered BigNumber conversion errors, complaining that I was trying to convert a scientific-notation number, for example "9.988e+22", into a BN. I added a fix to detect if result is a number in scientific notation and to subsequently convert it.

Specific edits:

  • Created a file to convert between exponential/scientific notation and numbers
  • Checked whether result in send() is in scientific notation, which is possible I believe because nodeJS sometimes automatically converts numbers >= 1e21 into scientific notation. See more here
  • To replicate the error, call web3.eth.getBalanceOf(address) on an address with a lot of ETH.

Other Changes

Checklist

Scripts

Added Scripts:

Updated Scripts:

Dependencies

Added Dependencies:

Updated Dependencies:

Related Issues

nicholaspai avatar Feb 20 '20 23:02 nicholaspai

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Mar 05 '20 14:03 CLAassistant