Solvedweb3.js Bignumber issue in web3 invalid number value (arg="_value", coderType="uint256", value=10000000000000000)
βοΈAccepted Answer
Heads up 2021 still remains a issue.
Other Answers:
Quick fixes:
const num256 = 42*10**18;
const fix1 = num256.toString();
const fix2 = "0x"+num256.toString(16);
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
web3@1.0.0-beta.37
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)
@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.
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.
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] })
web3 invalid number value (arg="_value", coderType="uint256", value=10000000000000000)
I am using web3 1.0.0-beta.36