Web3.js: Ethers encoder errors when processing Web3 BN values (beta.36)

Created on 5 Sep 2018  路  7Comments  路  Source: ChainSafe/web3.js

With a solidity method like:

function set(uint val) public {
  ..etc..
}

In beta.36this:

const val = web3.utils.toBN(1);
const data = myContract.methods.set(val).encodeABI();

throws this:

 Error: invalid number value (arg="val", coderType="uint256", value="1")
      at Object.throwError (/Users/cgewecke/code/consensys/e2e-beta36/wild-truffle/truffle/packages/truffle/build/webpack:/~/ethers/utils/errors.js:68:1)
      at CoderNumber.encode (/Users/cgewecke/code/consensys/e2e-beta36/wild-truffle/truffle/packages/truffle/build/webpack:/~/ethers/utils/abi-coder.js:353:1)
      at /Users/cgewecke/code/consensys/e2e-beta36/wild-truffle/truffle/packages/truffle/build/webpack:/~/ethers/utils/abi-coder.js:605:21

However this works:

const ethers = require('ethers');

const val = ethers.utils.bigNumberify(1);
const data = myContract.methods.set(val).encodeABI();
bug

Most helpful comment

Any update to this?

All 7 comments

This seems like a really big change to the web3 internals..is it better to use utils from ethers going forward?

Also getting this issue now when passing a BigNumber.js object directly. Breaking change.

 Error: invalid number value (arg="_tokenCap", coderType="uint256", value="300")
      at Object.throwError (node_modules/ethers/utils/errors.js:68:17)
      at CoderNumber.encode (node_modules/ethers/utils/abi-coder.js:353:20)
      at node_modules/ethers/utils/abi-coder.js:605:59

Maybe it is fixed in ethers.js 4.0.5? web3 beta.36 is still on ethers.js 4.0.1-beta.1

Stuck at same issue. Was working fine on beta.34.
@eyezick can confirm too that passing a BigNumber object directly also breaks.

Is it related to https://github.com/ethereum/web3.js/issues/1936#issuecomment-421032814 ?
Somehow passing hex works for me too.

Tagging @nivida & @frozeman for input over this.

Having the same issue, it works fine for Ganache but not working for Ropsten with Infura

Any update to this?

Updated ethers to the latest version in PR #2000 and this should fix it. Otherwise please open an issue in the ethers.js repository.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sundbry picture sundbry  路  3Comments

zamoore picture zamoore  路  3Comments

dzarezenko picture dzarezenko  路  3Comments

webersson picture webersson  路  3Comments

mishell-trickster picture mishell-trickster  路  3Comments