0

我使用web3.eth.estimateGas来计算数据交易的费用。我的代码如下:

var web3 = new Web3('https://bsc-dataseed1.binance.org:443');

var esGas;
web3.eth.estimateGas({
     "from"      : 'my address',       
     "nonce"     : 1, 
     "to"        : 'contract address',     
     "data"      : 'data'
}).then((result) => {
esGas = result; // always 81332 but Metamask is 89465
});
var gasPrice;

web3.eth.getGasPrice(function(e, r){
   gasPrice = r; // always 5 GWei like Metamask
});

使用以下命令,结果始终为0.00040666,而具有相同的“数据”

但是我使用了 Metamask,它的结果总是Max amount: 0.00044732 BNB

web3.utils.fromWei(gasPrice.toString(), 'ether') * esGas; // 0.00040666

谁能帮我解释一下?以及如何像 Metamask 一样计算?还是我的计算可以安全发送?

非常感谢

4

0 回答 0