关于以太坊之ethers库中的单位转换问题总结【存在一个很大的坑】

    xiaoxiao2023-11-21  155

     

    import { utils, } from "./modify_ethers/modify_ethers.js"; export default class Utils { static toWei ( amount ) { if (typeof ( amount ) !== "string") { throw Error( "这里的amount必须是一个string类型,不能进行类型转换,否则小数点超过6位ethers库会报异常【具体原因还未知】" ); } // parseUnits第一个参数amount必须是string类型,第二个参数代表小数点多少位【如果不传默认是18位】 return amount ? utils.parseUnits( amount, 18 ) : 0; } static fromWei ( amount ) { let wei = utils.bigNumberify( `${amount}` ); return amount ? utils.formatEther( wei ) : 0; } }

     

    最新回复(0)