[FAQ] web3js, Error: Please pass numbers as strings or BN objects to avoid precision errors.

我们在调用合约方法时,都可以传一些参数的,比如转账金额 value。

value 的单位是 wei,这是一个很小的单位,所以一般数值很大。

注意,把 ether 转 wei 需要先把 ether 的值转成字符串,不然就会报出标题中的错误。

比如 0.1 ether 转 wei 使用 web3.utils.toWei(this.inputEther.toString(), 'ether')。

反过来 wei 转 ether 使用 web3.utils.fromWei(xx, 'ether')

另外,这里有一个相关的错误,https://www.cnblogs.com/farwish/p/12424108.html

Link:https://www.cnblogs.com/farwish/p/12424066.html

原文地址:https://www.cnblogs.com/farwish/p/12424066.html