[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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM