0

I have created a DApp. In all my functions where I have used send() function of web3, I am facing above error.

I have a function in which I used call() and it worked fine but all send() using functions are failing with above error.

I have seen all possible answers online but no help, can someone please help me? I have very quick submission please

Moreover, the read functions are working fine on DAPP, so Im sure contract is initialized correctly and contract functions works fine as well without Dapp, so metamask is correct too.

web3 version in DApp = 1.0 Please someone help.

This is my failing transaction:

Contract.methods.AuctionInfo(deadline, maxBids).send({from: accounts[0], gas: '21000', value: (0.1*maxBids) * 1000000000000000000}, (error, result) => {
                    if (result) console.log(result);
                    if (error) console.log(error);
                });
  • Do you have the full source? Are you sure you are using web v0.20? .methods and .send are from v1.0. Also gas 21000 is too low and to calculate value it is better to use BigNumber. – Ismael Nov 17 at 0:58
  • sorry, v1.0. I have edited the question with it. You need complete app.js? – Fariha Abbasi Nov 17 at 1:09
  • 1
    Increasing the gas price to 210000 worked. Thanks. – Fariha Abbasi Nov 17 at 1:26
  • 1000000000000000000 > Number.MAX_SAFE_INTEGER. – goodvibration Nov 17 at 7:06
  • 1
    Change (0.1*maxBids) * 1000000000000000000 to `${maxBids}e17`. – goodvibration Nov 17 at 7:09
1

The comment-section indicates that your problem is solved.

Nevertheless, note that 1000000000000000000 is larger than Number.MAX_SAFE_INTEGER.

So the expression (0.1*maxBids) * 1000000000000000000 may yield an inaccurate value.

Therefore, assuming that the type of maxBids is Number, I recommend that you change it to:

`${maxBids}e17`

If maxBids == 12.34, for example, then the expression above will evaluate to the string "12.34e17".

And when you pass this string to your contract-function call, web3 will convert it to a BN instance which represents the integer value of 1234000000000000000 (1234 followed by 15 zeros).

Alternatively, since you are attempting to multiply 0.1*maxBids by 10 ** 18, you can simply use:

Web3.utils.toWei(0.1*maxBids)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.