Web3.js: Utils functions mention BigNumber instead of BN in error messages

Created on 6 Mar 2019  路  5Comments  路  Source: ChainSafe/web3.js

Description

Error messages for utils functions toWei, fromWei, etc. throw the following error:

Please pass numbers as strings or BigNumber objects to avoid precision errors.

The source itself checks if they are BN, not BigNumber. Relevant source (others in this file as well): https://github.com/ethereum/web3.js/blob/1.0/packages/web3-utils/src/index.js#L193

Steps to reproduce the behavior

  1. Import web3
  2. Call web3.utils.toWei(5) (i.e. pass in a number or other non-allowed type).

Error Logs

Gists

Versions

  • web3.js: 1.0.0 Beta 48
bug

All 5 comments

Yes, the documentation is wrong it's currently returning the BigNumber object but was always named BN. I will update the documentation and the related function documentation blocks.

It's also the thrown error messages (not sure if you are counting this in "documentation").

Since there is an isBigNumber in the source, with auto-conversion to BN e.g. here, why shouldn't toWei and fromWei accept BigNumber objects? Why force a manual conversion with toBN?

@rhlsthrm @interfect I can't really answer that because I do not the thoughts the former maintainer had. The whole BigNumber handling here in Web3.js will get improved asap.

@nivida are you going to use bignumber.js or BN? I'm migrating to beta now, and now I have to convert all BN objects to BigNumber, because bignumber is more convenient.

Was this page helpful?
0 / 5 - 0 ratings