Web3.js: Bug in uint256 type check? doesn't allow numbers over ~100e14

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

tokenSale.deploy({ data, arguments: [params.openingTime, params.closingTime, params.rate, params.wallet, 100e14, params.token, params.goal] }).send({
   from: '0xdeadbeef',
   gas: 5000000,
   gasPrice: 10e9,
}).then(console.log);

fails with:
Uncaught Error: invalid number value (arg="_cap", coderType="uint256", value=10000000000000000)

tokenSale.deploy({ data, arguments: [params.openingTime, params.closingTime, params.rate, params.wallet, 100e13, params.token, params.goal] }).send({
   from: '0xdeadbeef',
   gas: 5000000,
   gasPrice: 10e9,
}).then(console.log);

passes as normal (and any values smaller than 100e13

Most helpful comment

Ah, number inputs need to be in hex format:

const { toHex } = web3.utils;
const arguments = [toHex(params.openingTime), ...]

All 5 comments

It looks like this isn't a problem with web3. I think it's due to https://github.com/MetaMask/metamask-extension/issues/2350

I'm using MetaMask as web3 provider and I was using "web3": "^1.0.0-beta.36". So i downgraded to 0.2.0 which MetaMask requires and it works now. I only see this problem for deploying functions with large uint256 arguments in constructor

screen shot 2018-09-13 at 3 14 49 pm

My above comment, downgrading web3js deployed the contract. Then I realized all the arguments were set to "3.963877391197344453575983046348115674221700746820753546331534351508065746944e+75"

Ah, number inputs need to be in hex format:

const { toHex } = web3.utils;
const arguments = [toHex(params.openingTime), ...]

@mjdietzx Where did you get the info that all number inputs need to be in hex? In 1.0.0-beta34 we could send bignumber decimal strings into web3 without any problems. In 1.0.0-beta.36 there is this extra heuristic added that prevents us to send higher bignumbers to the API. So what piece of documentation or announcement did we miss?

@wigy-opensource-developer Look at this: https://github.com/ethereum/web3.js/issues/2077

Was this page helpful?
0 / 5 - 0 ratings