我得到了180亿美元的交易,我的项目是以美元计价的,所以我只需要发送正确的魏,我猜。
value: web3.utils.toWei(usdAmount, 'ether'),
字符串
我已经尝试了像
function usdToWei(usdAmount, ethToUsdExchangeRate) {
const weiPerEth = 10 ** 18; // 1 ETH = 10^18 wei
const amountInEth = usdAmount / ethToUsdExchangeRate;
const amountInWei = amountInEth * weiPerEth;
return amountInWei;
}
型
但我做错了。
1条答案
按热度按时间wtlkbnrh1#
假设
ethToUsdExchangeRate
是JavaScript中的一个Number
类型,它保存了以美元为单位的1 ETH的当前价格,包括小数(例如:$1234.56存储为1234.56
):字符串