Bignumber issue in web3 invalid number value (arg="_value", coderType="uint256", value=10000000000000000)
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] })
- When sending value 1e16 it throw error web3 invalid number value (arg="_value", coderType="uint256", value=10000000000000000)
- When sending value 10000000000000000 throw same error
- When sending value 1e16 as hex it work okay. No error.
- 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
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 . 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 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 what version of ethers.js do you think is good?
@gabmontes Hopefully the latest version has fixed it. (4.0.15) I will test it by own asap.
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'
This is also referenced in #1920 just fyi
The same issue in beta.37.
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 yes.
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!
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)
I am facing the same issue for latest web3 1.0.0 version
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 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.
I have the same error on Remix, after generating a smart contract from circom (0k knowledge proof).
@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.
The same issue on 1.0.0-beta.40
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.
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.