toWei method
单位转换:
Implementation
BigInt toWei({
required double fromEther, // 浮点值
int decimals = 18, // eth 默认
}) {
/// 换算单位: 10^x 幂
var unit = BigInt.from(10).pow(decimals);
/// 换算:
/// fix: from(double), 会取整舍入, 导致丢失精度, 要先做乘法
/// - https://www.woolha.com/tutorials/dart-using-bigint-examples
var ret = BigInt.from(fromEther * unit.toInt());
print('convert to wei: fromEther: $fromEther, unit:$unit, wei:$ret');
return ret;
}