例如:打开这个https://etherscan.io/tx/0xcb1e3530950cf2c43a307bcb5645ae71a12c76a60831617badd04aea3efe68aa
是随机的
我在网页上看到了这些信息:
Gas Limit:
136,500
Gas Used by Transaction:
35,531 (26.03%)
Gas Price:
0.000000008 Ether (8 Gwei)
Transaction Fee:
0.000284248 Ether ($0.05)我知道fee = gas_price x used_gas => 0.000000008 x 35,531 = 0.000284248 eth
太完美了。
I有兴趣通过api阅读以实际货币转换的交易费,就像您看到有一个$0.05
我不能一个api调用返回此信息的以太扫描。
我能做些什么才能得到这些信息?
呼叫
我只得到这些信息
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"blockHash": "0xd8d3b1532b376dcb34c6c36fc7bc167cfc048cfcb3cc53a9ab7dab7f383d4240",
"blockNumber": "0x961a86",
"from": "0xcc5ce245a296667aca1b5855f1a05ca950017e68",
"gas": "0x21534",
"gasPrice": "0x1dcd65000",
"hash": "0xcb1e3530950cf2c43a307bcb5645ae71a12c76a60831617badd04aea3efe68aa",
"input": "0x1cff79cd00000000000000000000000050b881ceafece2034b899205fbbd7bafc0c0d23000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000104a70e78c1000000000000000000000000f173214c720f58e03e194085b1db28b50acdeead000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca00000000000000000000000056178a0d5f301baf6cf3e1cd53d9863437345bf9000000000000000000000000000000000000000000000000a688906bd8b000000000000000000000000000000000000000000000000002bd494127192db3364000000000000000000000000000000000000000000000000000450ed6b3b61f2e000000000000000000000000000000000000000000000000000000005e8ee87a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000",
"nonce": "0x514",
"to": "0xa57bd00134b2850b2a1c55860c9e9ea100fdd6cf",
"transactionIndex": "0x4e",
"value": "0x0",
"v": "0x1c",
"r": "0xa03627e5bc49b850afb92774a4dc21c436da8bfe569688dfbd14fc9c58a2bdbb",
"s": "0x59ddaf4c96b60f413d713902abb1f802fbe3266afd3a61e82a8e635b44522fed"
}
}哪里
小数中的"gas": "0x21534" =>是136,500
小数中的"gasPrice"○: "0x1dcd65000" =>是8,000,000,000
这就是结果
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"blockHash": "0xd8d3b1532b376dcb34c6c36fc7bc167cfc048cfcb3cc53a9ab7dab7f383d4240",
"blockNumber": "0x961a86",
"contractAddress": null,
"cumulativeGasUsed": "0x778412",
"from": "0xcc5ce245a296667aca1b5855f1a05ca950017e68",
"gasUsed": "0x8acb",
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"to": "0xa57bd00134b2850b2a1c55860c9e9ea100fdd6cf",
"transactionHash": "0xcb1e3530950cf2c43a307bcb5645ae71a12c76a60831617badd04aea3efe68aa",
"transactionIndex": "0x4e"
}
}我在这里
"cumulativeGasUsed": "0x778412" => 7,832,594 [ what ??? ]
"gasUsed": "0x8acb" => 35,531 [ gas used by this transaction]因此,要重建网页信息,我需要2个api调用,以检索汽油价格和使用的天然气。
但我没有eth的报价,这才是我真正需要的
发布于 2020-04-09 09:44:12
例如,您可以使用CryptoCompare API:
const ETH_AMOUNT = "0.000284248";
const request = require("request");
const Decimal = require("decimal.js");
request.get("https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD", function(error, response, body) {
if (error)
throw new Error(error);
else if (!response)
throw new Error("no response");
else if (response.statusCode != 200)
throw new Error("bad response");
else
convert(JSON.parse(body).USD);
});
function convert(usdRate) {
const USD_AMOUNT = new Decimal(ETH_AMOUNT).mul(usdRate);
console.log(USD_AMOUNT.toFixed(2 /* decimal places */));
}发布于 2022-06-13 13:58:55
我只是在做一件类似的事情(但在发送tx之前,我会打电话)。
这个过程是为了
avgPriceUSD / 1000000000。这将给你每克威美元。有了这个,您现在可以进行查找了。如果你试图在过去为tx弄清楚这一点,你需要在某个时间点上得到这个价格。(您可以使用免费的coingecko api或您的首选项。)
我希望我正确地理解了你原来的问题。读回去,我可能会的。如果不是因为我得走了,我就把这个给删了。LOL。
发布于 2022-01-07 22:29:45
我不知道在此期间您是否能够解决这个问题,但从January 7 2022eth_getTransactionReceipt>开始,API调用D0返回一个名为effectiveGasPrice的字段,该字段对应于从eth_getTransactionByHash API调用(即"0x1dcd65000" )返回的相同值。
让我们进行另一项事务,在本例中:
0xf23766719c61461673d9e6f5cdc1e9ba42c958c07b924bfb9809cd58c244b4c0
来自effectiveGasPrice的eth_getTransactionReceipt:<#>0x19bbced2d3
来自gasPrice的eth_getTransactionByHash:0x19bbced2d3
换句话说,eth_getTransactionReceipt足以收回汽油价格和使用的天然气。
https://ethereum.stackexchange.com/questions/82315
复制相似问题