【发布时间】:2021-03-12 13:17:29
【问题描述】:
MetaMask中的事务关于值格式有问题,我把代码放在下面:
<script type="text/javascript">
const sendEthButton = document.querySelector('.sendEthButton');
sendEthButton.addEventListener('click', () => {
ethereum
.request({
method: 'eth_sendTransaction',
params: [
{
from: ethereum.selectedAddress,
to: '{{contractCreator}}',
value: '0x29a2241af62c0000',
},
],
})
.then((txHash) => console.log(txHash))
.catch((error) => console.error);
});
</script>
我已将 MetaMask 正确连接到站点和 Ganache,并且当我按下页面中的按钮时,交易也会出现在插件中,但只有在代码中使用此值时,我才能看到正确的一 (3),但我没有不知道格式如何...
我尝试过 web3.toWei(number, 'ether') 和 web3.toHex(number) 但它显示了奇怪的值...
例如,如果我用 web3.toWei(1, ether) 替换这个值,它会在 MetaMask 窗口中显示 4722.366483...
我在网上找到了这个值,但是我找不到解决这个问题的方法,谢谢大家!
【问题讨论】:
标签: javascript transactions ethereum web3 metamask