4

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

$ 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?

4

1 回答 1

6

您有几种计算汽油价格的方法。

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

  • RSK 统计
  • 准备交易时的Metamask/Nifty/MEW 建议gasPrice

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

如何获得gasPrice

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

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

$ 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"}

...但是,也请执行以下操作来计算缓冲区的数量:

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

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

如何获得minimumGasPrice

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

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

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",. 包含缓冲区的最后一步:

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

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

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

于 2021-01-13T13:04:24.227 回答