10

const result = await myContract.methods.myMethod(1).call();

brings the error from above. There is a simmilar questions here but since I use call gas shouldn't matter. I'm using "web3": "1.0.0-beta.35", (Beta.36 doesn't work for me at all.)

MarcS82
  • 323
  • 1
  • 3
  • 13

8 Answers8

10

Note that I believe this is fixed in the latest v3.0.0 of web3 which isn't out yet. This issue is now occuring for Binance Smart Chain. In the meantime, this fix worked for me:

https://github.com/ChainSafe/web3.js/pull/3948#issuecomment-821779691

Mauvis Ledford
  • 201
  • 2
  • 4
3

Are you using Quorum? If you are, this is probably because you are using RAFT consensus algorithm, you have to amend web3 or change to IBFT

Fernando Garcia
  • 366
  • 2
  • 6
1

Try using BigInt() to resolve this issue. BigInt is an object which provides a way to represent whole numbers larger than 253 - 1, which is the largest number JavaScript can reliably represent with the Number primitive.

Example:

const balance = await contractInstance.balanceOf(accounts[0]);
console.log('Balance of Account 0 =', BigInt(balance));
FLASH
  • 263
  • 3
  • 14
0

Ultimate Solution

Simple install web3 latest version which is version 4

npm install web3@v4.0.1-alpha.1

That solved my problem

Obot Ernest
  • 101
  • 3
0

That is Javascript integer limitation (Number.MAX_SAFE_INTEGER).

In order to work-around it, pass a String or as BigNumber instead.

For example:

const result = await myContract.methods.myMethod("1000000000000000000000").call();
const result = await myContract.methods.myMethod(new BigNumber(2).pow(54)).call();
goodvibration
  • 26,003
  • 5
  • 46
  • 86
  • In this case, await myContract.methods.myMethod("1").call(); – user19510 Sep 20 '18 at 17:26
  • @smarx: Yes, of course, but I don't see how this case (or any other case for that matter) could yield the error at the title. I guess he's doing something with the returned value which eventually causes this error (something which he hasn't posted here). – goodvibration Sep 20 '18 at 17:27
  • So you believe your answer is incorrect? – user19510 Sep 20 '18 at 17:30
  • I don't do anything with the answer. I also tried with a sting or BigNumber but without success. As a workaround I'm using truffle-contract now which works fine. – MarcS82 Sep 20 '18 at 17:49
  • @smarx: No, I believe that the question is missing some info. Either that, or there's a serious bug in "web3": "1.0.0-beta.35", which I sincerely doubt (though I've been using 34 for quite some time, so I'm possibly wrong on that one). – goodvibration Sep 20 '18 at 19:58
  • I'm not sure why you submitted this answer if you didn't think it would help. – user19510 Sep 20 '18 at 20:27
0

This will also happen if you set gasPrice to be some very large value when sending transaction like: 15e64.

Daniel
  • 359
  • 4
  • 16
0

In many blogs I've found it was a Truffle version problem. Truffle v5 would make problems of this type. They suggest to downgrade to truffle@4.1.15.

This has not been so for me. I have continue to use truffle v5. I've resolved by checking my gas limit when I sent a transaction. gasLimit: web3.utils.toHex( gas_limit ),//The maximum gas provided for this transaction (gas limit)

Node: v8.11.4 Truffle: 5.0.12 Web3: 1.0.0-beta.52 Truffle-contract: 4.0.11 Truffle-interface-adapter@0.1.2 │ └── web3@1.0.0-beta.37 └── web3@1.0.0-beta.37 Ganache-cli: v6.4.3 (ganache-core: 2.5.5) Ethereumjs-tx: 1.3.4

0

Check the contract code again please, You may have added some require(msg.sender == owner) like modifier and you code doesn't return some data which can be processed in client side.

gomozor
  • 51
  • 5