如何验证sendTransaction值?



在我的电子商务网站上,我想通过metamask添加ETH支付。我有发送交易的基本逻辑(见下文),它运行良好。

然而,当元掩码窗口弹出时,我能够编辑交易并更改交易值(例如:从0.1到0.0000000001)。我有一种感觉,这不是接受付款的正确方式,因为我无法确认交易价值。

我应该如何接受ETH支付?这是我目前所看到的:

const trans = await web3.eth.sendTransaction({
from: address,
to: 'xxx',
value: web3.utils.toWei('0.1', "ether"),
});

这可能不是最好的方法,但我能够将sendTransaction值与返回的事务进行比较。

const confirm = await web3.eth.getTransaction(trans.transactionHash);
console.log(web3.utils.fromWei(confirm.value, "ether"));

最新更新