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

Support toFixed method on BigNumbers #2675

Closed
rhlsthrm opened this issue Apr 12, 2019 · 5 comments
Closed

Support toFixed method on BigNumbers #2675

rhlsthrm opened this issue Apr 12, 2019 · 5 comments

Comments

@rhlsthrm
Copy link

Description

web3.eth.abi.decodeLog now returns ethers.js BigNumber instances (which itself is inconsistent seeing as how Web3 removed BigNumber in favor of BN.js). These BigNumber instances do not support the method toFixed(). toString() can be unsafe, so we would like to only use toFixed(). Alternatively, support for getting the decoded data as strings instead of BigNumbers is an acceptable workaround.

Expected behavior

Calling bigNumberInstance.toFixed() should work.

Actual behavior

Calling bigNumberInstance.toFixed() returns an error.

Steps to reproduce the behavior

See Gist.

Error Logs

Gists

https://gist.github.com/rhlsthrm/9c198a5c4537a01fa521c97f0e785801

Versions

  • web3.js: Beta 52
  • nodejs:
  • browser:
  • ethereum node:
@princesinha19
Copy link
Contributor

The BN.js library is only for integers that's why it doesn't support toFixed (). Can you explain why toString() can be unsafe?

@nivida
Copy link
Contributor

nivida commented Apr 14, 2019

We get the BigNumber object from ethers.js. Could you please open an issue in the ethers.js repository?

@nivida nivida closed this as completed Apr 14, 2019
@bohendo
Copy link

bohendo commented Apr 18, 2019

@princesinha19 I see in the docs of bignumber.js that calling .toString() of a very large number might return a number in exponent-form which would likely cause problems & might be where the concern is coming from.

But the more recent version of ethers depends on bn.js which does not have this problem.

So looks like this might be a false alarm..?

@princesinha19
Copy link
Contributor

Yes right @bohendo. But, it's a problem of ethers.js because we are using ethers.js for BigNumber Object so, I think this should be solved by ethers.js.

@rhlsthrm
Copy link
Author

Yes @bohendo it looks like ethers calls it BigNumber but it's actually bn.js so it's not an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants