本文介绍了如何计算用于 RSK 交易的天然气价格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何为我在 RSK 网络上的交易设置合适的汽油价格.我熟悉以太坊的 eth_gasPrice 方法:

I need to know how to set a proper gas price for my transactions on RSK network. I am familiar with the eth_gasPrice approach from Ethereum:

$ curl https://public-node.testnet.rsk.co -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":1}'
{"jsonrpc":"2.0","id":1,"result":"0x3938700"}

以上是否也推荐用于 RSK?

Is the above recommended for RSK as well?

推荐答案

您有多种计算 gas 价格的方法.

You have several ways to calculate the gas price.

最终用户的角度来看,您可以从以下位置获取汽油价格:

From an end user point of view, you can get the gas price from:

开发者的角度来看,您需要知道 RSK 有一个 minimumGasPrice 限制,这意味着如果您设置了 gasPrice低于该最小值,您的交易将被拒绝.

From a developer point of view, you need to know that RSK has a minimumGasPrice limit, this means that if you set a gasPrice below that minimum, your transaction will be rejected.

如何获得gasPrice:

使用 JSON-RPC 方法 eth_gasPrice.这为您提供了网络中当前的平均汽油价格.最好指定额外 5% 的 Gas 价格作为缓冲,以高于平均 Gas 价格.

Using JSON-RPC method eth_gasPrice. This gives you a current average gas price in the network. It's a good idea to specify an additional 5% gas price as a buffer, in order to be above the average gas price.

您上面的示例代码是正确的:

The example code above you have is correct:

$ curl https://public-node.testnet.rsk.co -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":1}'
{"jsonrpc":"2.0","id":1,"result":"0x3938700"}

...但是,请执行以下操作以使用缓冲区计算数量:

... however, do the following as well to calculate the amount with buffer:

$ node -e "console.log(0x3938700 / 20 * 21);"
63000000

eth_gasPrice 返回 6000 万,但我们在提交交易时使用了 6300 万.对于那些熟悉以太坊开发的人来说,这是与您在那里使用的相同方法.

eth_gasPrice returns 60 million, but we use 63 million when submitting transactions.For those familiar with Ethereum development, this is the same method as you would use there.

如何获得minimumGasPrice:

使用 JSON-RPC 方法 eth_getBlockByNumber,以最佳区块编号作为参数,并从响应中获取 minimumGasPrice.由于最低 gas 价格可能在区块之间变化 1%,请参阅 RSKIP-09,建议额外指定 10% 的 gas 价格作为缓冲,以确保有效 gasPrice 的 10 个区块窗口.这迎合了悲观的情况.

Using JSON-RPC method eth_getBlockByNumber with best block number as parameter and getting minimumGasPrice from the response. As the minimum gas price may change 1% between blocks, see RSKIP-09, it is recommended to specify an additional 10% gas price as buffer, to ensure a 10 block window of valid gasPrice. This caters to a pessimistic scenario.

执行上述操作的示例代码:

Example code to perform the above:

curl https://public-node.testnet.rsk.co -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest",false],"id":1}'
{
   "jsonrpc" : "2.0",
   "result" : {
      "cumulativeDifficulty" : "0x2b7cd0b2",
      "size" : "0xbcc",
      "uncles" : [],
      "gasUsed" : "0x546fe",
      "hash" : "0x68abc09397ec6ae77acf52c195638dd9f93e5756eb1856c81e8e30cbbeef6b39",
      "difficulty" : "0x2b7cd0b2",
      "miner" : "0x1fab9a0e24ffc209b01faa5a61ad4366982d0b7f",
      "bitcoinMergedMiningMerkleProof" : "0x8bfb89a6e8a8fa0fee018e9dd0d86c0aea40806d3e8fe45e9454a250b763d978c812164690d7af62b31743db9944cc5ac6038d210ef6d1e4fb08c712f9a318c0538845ed4d3f3b61879aba5e79c58bc754213a9872f54c2da44051b3c0e04d4be382b6f1303386afc08c991a85aae39fa3263cbcbd9d4a05d8a2d0797204902de56af20198ad4a3b2c553e0c2500da50a536fd10233204c5a9837802f6816f740a146e58ebae0d7be3ca3a79f7d2a942e5ade058baa53e252162fefc136f33434e84753446aad913ea4baafd6bcaa145d37b9b3b85fec42d7bf47d5efef8e000",
      "paidFees" : "0x1395b92f0000",
      "stateRoot" : "0xb7fc903f8f60a3e0d0d80ea58348e9637e3a9a4c8f9de6e089326c9bfbb698ed",
      "transactions" : [ "<< redacted for brevity >>" ],
      "totalDifficulty" : "0x2eff7f12ec2c2655d",
      "bitcoinMergedMiningHeader" : "0x00000020901806378d89a22c6aaa772bab42ec41dfdb4dce77d361181600000000000000a0782738fa6b7ef70644de0aca393597462d9fb97d59c92680eba5e5a2b66af14c6efe5f5c75161904657655",
      "receiptsRoot" : "0xc930346e224a837fc426b900c07d3f744f4c82ac789d05624dbbe4e008dc2f22",
      "hashForMergedMining" : "0xb58502263dd8363d0c88287eb3436c731ff5763e5ed4d4919306b028001738f9",
      "transactionsRoot" : "0x9cc25cf985416ef18fa171f59b9d03f6921bad3c93f956dc0d472f9429b81167",
      "gasLimit" : "0x67c280",
      "bitcoinMergedMiningCoinbaseTransaction" : "0x00000000000000801d9be7d007fe4505303282a8fdd52df91d1292256a776a2181521c4513ee6c246088ac0000000000000000266a24aa21a9edee78f53b94245e73c99fb98a96b539836fa82b85a20de1c0d7984f0eabd198f600000000000000002a6a52534b424c4f434b3ab58502263dd8363d0c88287eb3436c731ff5763e5ed4d4919306b028001738f900000000",
      "logsBloom" : "0x00000000000000000000001000000008000000000040000000000000000000000000400000050000000400000000000400000000010000000000000000000000000000000080000000000004000000000000000000000080000000004000000000000000800000000000001000000000000000000000000002000008080000000000000000000000000001000208000000000000040000000000000420080000000000020008100000000000020010000080000000000082001000000000000000000001040000000000000000080000000030000001000880200004100200000000000020000000002000000000100000000000000000010200000000000000",
      "minimumGasPrice" : "0x387ee40",
      "timestamp" : "0x5ffe6e40",
      "number" : "0x1738f9",
      "parentHash" : "0x1276aa271525f757166acf767cd6100a25d0cba18f6caf925299276f3d439404",
      "sha3Uncles" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
      "extraData" : "0xd1018f504150595255532d62643739313837"
   },
   "id" : 1
}

对此的响应非常大(见上文),但是,它确实包含我们需要的信息:"minimumGasPrice":0x387ee40",.包含缓冲区的最后一步:

The response for this is pretty large (see above), however, it does contain the info we need: "minimumGasPrice" : "0x387ee40",. The final step to include the buffer:

$ node -e "console.log(0x387ee40 / 10 * 11);"
65164000

eth_getBlockByNumber.minimumgasPrice 返回大约 5900 万,但我们在提交交易时使用大约 6500 万.

eth_getBlockByNumber.minimumgasPrice returns approximately 59 million, but we use approximately 65 million when submitting transactions.

对于那些熟悉以太坊开发的人来说,这种方法是不同的,并且只能在 RSK 上使用.

For those familiar with Ethereum development, this is approach is different and only available on RSK.

这篇关于如何计算用于 RSK 交易的天然气价格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-16 12:15