【发布时间】:2020-07-28 00:44:42
【问题描述】:
我想估算一下在两个地址之间进行简单 ERC20 转账的 gas。 estimateGas 上的 web3.js 文档确实令人困惑:
// using the callback
myContract.methods.myMethod(123).estimateGas({gas: 5000000}, function(error, gasAmount){
if(gasAmount == 5000000)
console.log('Method ran out of gas');
});
myMethod(123) 让我感到困惑。那是做什么用的?以下是我目前的想法,但我得到了TypeError: contract.methods.send is not a function。我应该用什么代替myMethod(123)?
try {
await contract.methods
.send("0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe")
.estimateGas({ gas: 60000 }, (error, gasAmount) => {
return gasAmount;
});
} catch (err) {
console.log(err);
}
【问题讨论】: