【发布时间】:2022-08-20 16:58:23
【问题描述】:
我正在尝试将ETH 从一个帐户发送到另一个帐户,但从ETH 到WEI 的转换一直让我头疼。在这种情况下,我尝试发送0.11 ETH,但在确认窗口中,我收到了313.59464925 ETH。
// This is my transaction code
await window.ethereum
.request({
method: \"eth_sendTransaction\",
params: [
{
from: window.ethereum.selectedAddress,
to: \"0x4dxxxxxxxxxxxxxxxxxx2dr9820C\",
value: String(0.11 * 1000000000000000000), // convert to WEI
},
],
})
.then((result) => console.log(result))
.catch((error) => console.log(error));
我也尝试过使用BigNumber,但它并没有解决问题,我想我搞砸了。如何准确地将ETH 转换为WEI?
-
将
String(0.11 * 1000000000000000000)更改为\"11e+17\",或使用BigNumber(或在您的问题中解释您究竟如何尝试使用BigNumber)。 -
顺便说一句,不确定您对
eth_sendTransaction的期望是什么,但该交易的结果应该是一个简单的交易哈希,而不是一定数量的 ETH 或类似的东西。将该散列转换为数值是毫无意义的。
标签: blockchain ethereum metamask