web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Bignumber issue in web3 invalid number value (arg="_value", coderType="uint256", value=10000000000000000)

Open patidarmanoj10 opened this issue 8 years ago • 66 comments

Getting invalid number error when calling a method of a contract which take uint256 argument.

Example: myContract.methods.transfer(accounts[1], 1e16).send({ from: accounts[0] })

  1. When sending value 1e16 it throw error web3 invalid number value (arg="_value", coderType="uint256", value=10000000000000000)
  2. When sending value 10000000000000000 throw same error
  3. When sending value 1e16 as hex it work okay. No error.
  4. When sending value 1e15 or less value as number like 100000000000000 if work okay. No error

I am using web3 1.0.0-beta.36

patidarmanoj10 avatar Nov 29 '18 20:11 patidarmanoj10

Thanks for submitting this issue! I think this an issue of the new AbiCoder from ethers.js I will update the ethers.js package and test it.

nivida avatar Nov 30 '18 03:11 nivida

@nivida . More details- I tested in old version of web3 . This is not in issue in beta.35 and beta.34 . Seems like breaking in beta.36 only.

patidarmanoj10 avatar Nov 30 '18 18:11 patidarmanoj10

@patidarmanoj10 Yes this is because we use the new AbiCoder of ethers.js since beta36. This should be fixed quickly and released with the next build thanks for testing it. My plan is to write the AbiCoder by my self after the 1.0 stable release because it's dangerous to have such an important part of this lib as external dep. :-)

nivida avatar Nov 30 '18 18:11 nivida

@nivida what version of ethers.js do you think is good?

gabmontes avatar Nov 30 '18 21:11 gabmontes

@gabmontes Hopefully the latest version has fixed it. (4.0.15) I will test it by own asap.

nivida avatar Dec 01 '18 12:12 nivida

I was able to reproduce the bug in version 4.0.15:

> ethersAbiCoder.encode(['uint256'], [1e+14])
'0x00000000000000000000000000000000000000000000000000005af3107a4000'
> ethersAbiCoder.encode(['uint256'], [1e+16])
Error: invalid number value (arg="", coderType="uint256", value=10000000000000000, version=4.0.15)
    at Object.throwError (/private/tmp/node_modules/ethers/errors.js:76:17)
    at CoderNumber.encode (/private/tmp/node_modules/ethers/utils/abi-coder.js:390:20)
    at /private/tmp/node_modules/ethers/utils/abi-coder.js:642:59
    at Array.forEach (<anonymous>)
    at pack (/private/tmp/node_modules/ethers/utils/abi-coder.js:641:12)
    at CoderTuple.encode (/private/tmp/node_modules/ethers/utils/abi-coder.js:801:16)
    at AbiCoder.encode (/private/tmp/node_modules/ethers/utils/abi-coder.js:938:77)
> ethersAbiCoder.encode(['uint256'], [1e+15])
'0x00000000000000000000000000000000000000000000000000038d7ea4c68000'

markerdmann avatar Dec 03 '18 18:12 markerdmann

This is also referenced in #1920 just fyi

eyezick avatar Dec 04 '18 21:12 eyezick

The same issue in beta.37.

ecouffes avatar Dec 17 '18 08:12 ecouffes

Any update on this issue?? I just met in beta.37.

@patidarmanoj10 , you mentioned

When sending value 1e16 as hex it work okay. No error.

Does that mean a workaround for this issue?? If I convert my number to that format.

Thanks!

yueawang avatar Dec 25 '18 13:12 yueawang

@yueawang yes.

patidarmanoj10 avatar Dec 26 '18 17:12 patidarmanoj10

In addition to the BigNumber issue we are also getting an error with Bytes3: Error: invalid bytes3 value (arg="ccy", coderType="bytes3", value="USD")

Workaround: web3.utils.asciiToHex('USD')

We are using truffle 5.0.1 and most unit tests are failing due to this error.

Any update on if/when this issue will be resolved?

Many thanks!

macro88 avatar Jan 08 '19 09:01 macro88

I'm using the following truffle version and this same issue is cropping up: Truffle v5.0.2 (core: 5.0.2) Solidity v0.5.0 (solc-js) Node v11.6.0 [email protected]

once I allocate a value greater than 1e15 to uint256 (like 1e16, or 1e17), it breaks and throws an error during truffle deployment of contract (using constructor arguments):

Error: invalid number value (arg="_var", coderType="uint256", value=10000000000000000)

kombos avatar Jan 17 '19 08:01 kombos

I am facing the same issue for latest web3 1.0.0 version

0x-genesys avatar Jan 22 '19 11:01 0x-genesys

This should be solved in this git tag and will be released within the next week: https://github.com/ethereum/web3.js/tree/v1.0.0-beta.38-rc2

Would be great if someone could quickly test it for me.

nivida avatar Jan 22 '19 12:01 nivida

@nivida It looks like I'm still getting the error:

Error: invalid BigNumber string value (arg="value", value="1e+24", version=4.0.21)

I cloned Truffle, checked out v5.0.2, cloned web3 inside truffle/packages and checked out v1.0.0-beta.38-rc2, and then updated relevant package.json files to point everything in my project and in truffle to that version of web3. Not sure if that's the easiest way to do it, but the stack trace for the error above is pointing to mytruffle/packages/truffle-contract/node_modules/ethers/errors.js:76:17.

Edit: I think the problem is just that it's still pointing to the wrong version of web3-eth-abi and ethers. I'll look for a better way to replace web3 in my local clone of truffle.

markerdmann avatar Jan 22 '19 22:01 markerdmann

I have the same error on Remix, after generating a smart contract from circom (0k knowledge proof).

GuthL avatar Jan 23 '19 15:01 GuthL

@markerdmann I will release a Web3.js version with the latest release of ethers.js. But as I saw are you already using the latest version of ethers.js version=4.0.21. Because of this would I recommend to open an issue in the ethers.js repository for fixing this.

nivida avatar Jan 25 '19 10:01 nivida

The same issue on 1.0.0-beta.40

inyutin avatar Jan 29 '19 22:01 inyutin

Same issue also on 1.0.0-beta.41.

@nivida I made a little dig into code the of ethers.js and found that they are using their own implementation of bignumber. So when I (and the others I suppose) talk about bignumber.js, ethers got their own implementation.

In beta.36 ethers.js was introduced to web3-eth-abi and since than it's not functioning with bignumber.js.

leonprou avatar Feb 04 '19 11:02 leonprou

I had the same error when passing wei values in truffle tests and my temporary solution is using web3.utils.toWei which seems to work. Maybe someone will find this helpful as an interim solution.

protortyp avatar Feb 06 '19 21:02 protortyp