【问题标题】:How to calculate optimal gas limit and gas price?如何计算最优gas limit和gas price?
【发布时间】:2018-11-30 02:49:18
【问题描述】:

我正在训练写 Solidity,当我尝试在区块链中下载 ERC20 示例时,我需要选择 gas 限制和 gas 价格。如何计算最优? https://www.ethgasstation.info 说用 5 gwei gas 价格确认时间是 0.46 分钟,是真的吗?我看了论坛,我觉得这太少了

ERC20 转账需要多少 gas 限制?

【问题讨论】:

  • 我投票决定将此问题作为题外话来结束,因为如果它属于任何地方,它就属于以太坊的专门 SO
  • web3js 库有 web3.eth.estimateGasweb3.eth.getGasPrice 方法可以帮助你。

标签: ethereum smartcontracts cryptocurrency


【解决方案1】:

你可以这样计算

const gasPrice = await web3.eth.getGasPrice();
const gasPriceLimit = await web3.eth.estimateGas({
     "from"      : walletbase,       
     "nonce"     : value, 
     "to"        : contractAddr,     
     "data"      : data
})

【讨论】:

    猜你喜欢
    • 2022-12-30
    • 2022-06-11
    • 1970-01-01
    • 2017-08-15
    • 2018-05-03
    • 2019-04-18
    • 2021-11-19
    • 2018-03-20
    • 2019-01-03
    相关资源
    最近更新 更多