[Ethereum] Error: Please pass numbers as strings or BigNumber objects to avoid precision errors

bignumbergo-ethereumtruffletruffle-testweb3js

let result = await instance.joinQuiz({
    from: accounts[1],
    value: web3.utils.toWei(10, "wei")
});

Best Answer

The signature of the toWei method is (can be found in the docs.

web3.utils.toWei(number [, unit])

number - String|BN: The value.
unit - String (optional, defaults to "ether"): The ether to convert from.

So you should provide the number as either a String or a BigNumber (Web3 0.2x) / BN (Web3 1.x).

Your code should then be:

let result = await instance.joinQuiz({
    from: accounts[1], 
    value: web3.utils.toWei("10", "wei")
});

However, in your code you're converting from wei to wei, which might not be what you want, so keep in mind that the second parameter is the unit you're converting from.

Related Topic