如何使用 web3.js 获得 RSK 的最低 gas 价格?

Posted

技术标签:

【中文标题】如何使用 web3.js 获得 RSK 的最低 gas 价格?【英文标题】:How to get the minimum gas price on RSK with web3.js? 【发布时间】:2021-04-08 06:56:23 【问题描述】:

我正在使用 web3.js 来获得最低 gas 价格,但以下方法不起作用:

web3.eth.getBlock('latest').minimumGasPrice

我该怎么做?

【问题讨论】:

【参考方案1】:

您可以像这样使用 web3.js 做到这一点:

const block = await web3.eth.getBlock('latest');
const minimumGasPrice = block.minimumGasPrice;

注意getBlock()涉及网络请求, 因此需要await

您的问题只询问了一种在 javascript 中执行此操作的方法, 但是如果你想使用 终端命令 来做同样的事情, 如果您还没有这样做, 查看这个类似问题的答案: How to calculate what gas price to use for transactions on RSK?

注意:如果您来自以太坊开发, 此 RPC 响应中的 minimumGasPrice 字段仅限 RSK - 不要对以太坊抱有同样的期望。

【讨论】:

以上是关于如何使用 web3.js 获得 RSK 的最低 gas 价格?的主要内容,如果未能解决你的问题,请参考以下文章