[英]ethers.js: provider.getGasPrice()
In ethers.js
you can use provider.getGasPrice()
to get a best-guess estimate of the gas you should pay.在ethers.js
,您可以使用provider.getGasPrice()
来获得您应该支付的 gas 的最佳估计。 Is there anything simple I can call or transform onto this value in order to get what an equivalent of a "Fast" transaction would be instead of an "Average" speed transaction?有什么简单的东西我可以调用或转换到这个值,以获得相当于“快速”交易而不是“平均”速度交易的东西吗?
The getGasPrice()
queries your provider JSON-RPC method eth_gasPrice and simply proxies whathever your provider returned. getGasPrice()
查询您的提供者 JSON-RPC 方法eth_gasPrice并简单地代理您的提供者返回的任何内容。
In order to calculate the "Fast" and "Average" speed, you'll need to define what you consider these metrics.为了计算“快速”和“平均”速度,您需要定义您认为这些指标的内容。 For example you can collect all transactions within the last 20 blocks (approx. 5 minutes) and look for percentiles in the historic data:例如,您可以收集最近 20 个区块(大约 5 分钟)内的所有交易,并在历史数据中查找百分位数:
You can get transactions in a block using the getBlockWithTransactions() ethers.js method.您可以使用getBlockWithTransactions() ethers.js 方法获取块中的交易。 In each transaction you're looking for the gasPrice
property.在每笔交易中,您都在寻找gasPrice
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.