Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimism API - eth_getBlockByNumber giving incorrect response #35

Open
bmalepaty opened this issue Jul 25, 2022 · 5 comments
Open

Optimism API - eth_getBlockByNumber giving incorrect response #35

bmalepaty opened this issue Jul 25, 2022 · 5 comments

Comments

@bmalepaty
Copy link

bmalepaty commented Jul 25, 2022

The API query for eth_getBlockByNumber does not give correct "gas", "gas price", and "L1BlockNumber" details.
Query:
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "id": 5, "method": "eth_getBlockByNumber", "params": ["0xdb58de", true]}' "https://opt-mainnet.g.alchemy.com/v2/<MY_API_ID>"

Response:
{ "jsonrpc": "2.0", "id": 5, "result": { "number": "0xdb58de", //14375134 "difficulty": "0x2", "extraData": "0xd98301090a846765746889676f312e31352e3133856c696e7578000000000000c3ab3a2a0ffb1ca35b12967d4f5efd4ee64ee06202e344c4e339859d9b71883b28c9ea423a8b08aa9ae08101fd7240dcbbf0e28ddb0796b5a8c9e358d34f69f201", "gasLimit": "0xe4e1c0", //15000000 "gasUsed": "0x3540d", //218125 //l2 gas used by tx "hash": "0x830e63c03eadc3108bf8bb7cc35cb51fd35350b73dc11a9a9cdbf2a8f3c33aad", "logsBloom": "0x00000002000400000000009000000000000000000000000404040000000000000001000000000000000000100000000000000040000020000000010000040000000000800000000800000008000000000000000000000000000004008000000010000000000000000000101000010000000000020000000000000010800800000000000000000000000000000000000000000401002000000000001000000000000000000000000000000000800001000000000000000000000000000000000000020002000000000000000000800000000000000000000000000000000000000000000000010000000000000000000400000000008000400000000000011000", "miner": "0x0000000000000000000000000000000000000000", "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "nonce": "0x0000000000000000", "parentHash": "0x7dba5ebb8615d4e23432ee60c952d5adde1f1edf503b39bbd92bc9ce96e62a61", "receiptsRoot": "0x51f4c4552350dcdf04b3ec837b3f256dda48e31e02fc5e6e0721164c61065578", "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", "size": "0x97d", "stateRoot": "0xfc4400d157b2f193862a6ceebded34d9f1723cc5b57b0419b5cecb69d5284bc7", "timestamp": "0x62ce8900", //1657702656 "totalDifficulty": "0x1b6b1bd", "transactions": [ { "hash": "0x815804d4fdf5786ff955658f21191fcdf34c7ad437d0d5f517ff83b4a97325cf", \\tx hash "blockHash": "0x830e63c03eadc3108bf8bb7cc35cb51fd35350b73dc11a9a9cdbf2a8f3c33aad", "blockNumber": "0xdb58de", //14375134 "from": "0xc6c3e4bbcdc719e7b5793a31a36937f729605c33", "gas": "0x4f294", //324244 "gasPrice": "0xf4240", //1000000 //l2gasprice "index": "0xdb58dd", //14375133 "input": "0x415565b0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c31607000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000000000000a1045f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000460000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042000000000000000000000000000000000000060000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c31607000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000012556e6973776170563300000000000000000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000000000000a1045f000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000e592427a0aece92de3edee1f18e0157c058615640000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002b42000000000000000000000000000000000000060001f47f5c764cbc14f9669b88837ca1490cca17c31607000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000004200000000000000000000000000000000000006000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000000000869584cd0000000000000000000000003ce37278de6388532c3949ce4e886f365b14fb5600000000000000000000000000000000000000000000001f4a14c6b462ce88f1", "l1BlockNumber": "0xe6ea7d", //15133309 "l1Timestamp": "0x62ce8900", "nonce": "0x5a", //90 "queueOrigin": "sequencer", "r": "0x9ee8e6c2f2916d0cf16cbe3b1ae1d58b39f7edfdc740b39d2b72882ab6867393", "rawTransaction": "0xf907145a830f42408304f29494def1abe32c034e558cdd535791643c58a13acc10872386f26fc10000b906a8415565b0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c31607000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000000000000a1045f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000460000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042000000000000000000000000000000000000060000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c31607000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000012556e6973776170563300000000000000000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000000000000a1045f000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000e592427a0aece92de3edee1f18e0157c058615640000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002b42000000000000000000000000000000000000060001f47f5c764cbc14f9669b88837ca1490cca17c31607000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000004200000000000000000000000000000000000006000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000000000869584cd0000000000000000000000003ce37278de6388532c3949ce4e886f365b14fb5600000000000000000000000000000000000000000000001f4a14c6b462ce88f138a09ee8e6c2f2916d0cf16cbe3b1ae1d58b39f7edfdc740b39d2b72882ab6867393a00194b4bf431dc430facd52bea4e1e00f5609cb43a3ab12d7b6951e7959c0105f", "s": "0x194b4bf431dc430facd52bea4e1e00f5609cb43a3ab12d7b6951e7959c0105f", "to": "0xdef1abe32c034e558cdd535791643c58a13acc10", "transactionIndex": "0x0", "v": "0x38", //56 "value": "0x2386f26fc10000" //10000000000000000 wei } ], "transactionsRoot": "0xf27d553d0d8dd4d0166056ec016f94e329106529a59f827fe1d7b7181ddfae7f", "uncles": [] } }

The response does not have all gas details required to calculate transaction fee. Also L1 block number as per explorer (https://optimistic.etherscan.io/batch/91177) is 15133361, but response shows 15133309.
To calculate transaction fee, "gasprice", "gasused", "l1gasprice", "l1gasused", and "l1feescalar" are required as per explorer (https://optimistic.etherscan.io/tx/0x815804d4fdf5786ff955658f21191fcdf34c7ad437d0d5f517ff83b4a97325cf). But all values are missing from the response.
The response has gas limit instead of gas used, and L1 gas details are missing

@elanh
Copy link
Collaborator

elanh commented Jul 27, 2022

Hey! How are you getting this result? I'm unable to repro it based off the request you sent. Here's the request:

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "id": 5, "method": "eth_getBlockByNumber", "params": ["0x1", false]}' "https://opt-mainnet.g.alchemy.com/v2/demo"

And response:

{"jsonrpc":"2.0","id":5,"result":{"number":"0x1","difficulty":"0x2","extraData":"0xd98301090a846765746889676f312e31352e3133856c696e75780000000000009c3827892825f0825a7e329b6913b84c9e4f89168350aff0939e0e6609629f2e7f07f2aeb62acbf4b16a739cab68866f4880ea406583a4b28a59d4f55dc2314e00","gasLimit":"0xe4e1c0","gasUsed":"0x3183d","hash":"0xbee7192e575af30420cae0c7776304ac196077ee72b048970549e4f08e875453","logsBloom":"0x00000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000400000000000100000000000000200000000002000000000000001000000000000000000004000000000000000000000000000040000400000100400000000000000100000000000000000000000000000020000000000000000000000000000000000000000000000001000000000000000000000100000000000000000000000000000000000000000000000000000000000000088000000080000000000010000000000000000000000000000800008000120000000000000000000000000000000002000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","parentHash":"0x7ca38a1916c42007829c55e69d3e9a73265554b586a499015373241b8a3fa48b","receiptsRoot":"0xf4c97b1186b690ad3318f907c0cdaf46f4598f27f711a5609064b2690a767287","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x30c","stateRoot":"0xd3ac40854cd2ac17d8effeae6065cea990b04be714f7061544973feeb2f1c95f","timestamp":"0x618d8837","totalDifficulty":"0x3","transactions":["0x5e77a04531c7c107af1882d76cbff9486d0a9aa53701c30888509d4f5f2b003a"],"transactionsRoot":"0x19f5efd0d94386e72fcb3f296f1cb2936d017c37487982f76f09c591129f561f","uncles":[]}}%

You can also verify this by using the composer tool.

@bmalepaty
Copy link
Author

bmalepaty commented Jul 27, 2022

Hey! How are you getting this result? I'm unable to repro it based off the request you sent. Here's the request:

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "id": 5, "method": "eth_getBlockByNumber", "params": ["0x1", false]}' "https://opt-mainnet.g.alchemy.com/v2/demo"

And response:

{"jsonrpc":"2.0","id":5,"result":{"number":"0x1","difficulty":"0x2","extraData":"0xd98301090a846765746889676f312e31352e3133856c696e75780000000000009c3827892825f0825a7e329b6913b84c9e4f89168350aff0939e0e6609629f2e7f07f2aeb62acbf4b16a739cab68866f4880ea406583a4b28a59d4f55dc2314e00","gasLimit":"0xe4e1c0","gasUsed":"0x3183d","hash":"0xbee7192e575af30420cae0c7776304ac196077ee72b048970549e4f08e875453","logsBloom":"0x00000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000400000000000100000000000000200000000002000000000000001000000000000000000004000000000000000000000000000040000400000100400000000000000100000000000000000000000000000020000000000000000000000000000000000000000000000001000000000000000000000100000000000000000000000000000000000000000000000000000000000000088000000080000000000010000000000000000000000000000800008000120000000000000000000000000000000002000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","parentHash":"0x7ca38a1916c42007829c55e69d3e9a73265554b586a499015373241b8a3fa48b","receiptsRoot":"0xf4c97b1186b690ad3318f907c0cdaf46f4598f27f711a5609064b2690a767287","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x30c","stateRoot":"0xd3ac40854cd2ac17d8effeae6065cea990b04be714f7061544973feeb2f1c95f","timestamp":"0x618d8837","totalDifficulty":"0x3","transactions":["0x5e77a04531c7c107af1882d76cbff9486d0a9aa53701c30888509d4f5f2b003a"],"transactionsRoot":"0x19f5efd0d94386e72fcb3f296f1cb2936d017c37487982f76f09c591129f561f","uncles":[]}}%

You can also verify this by using the composer tool.

"params": ["0x1", false]} - The second argument should be true - Sorry, It was a typo - Edited my query too
Composer URL

@elanh
Copy link
Collaborator

elanh commented Jul 29, 2022

And which part of this response is incorrect? Looks accurate to me as far as I can tell

@bmalepaty
Copy link
Author

  1. The L1 block number is incorrect
    - As per the response, it is: "l1BlockNumber": "0xe6ea7d", which when converted to decimal would be "15133309"
    - But as per explorer, the tx hash belongs to Batch 91171 which has L1 block number of "15133361"

image
image

  1. The response does not provide any transaction fee details. To calculate transaction fee, "gasprice", "gasused", "l1gasprice", "l1gasused", and "l1feescalar" are required as per explorer (https://optimistic.etherscan.io/tx/0x815804d4fdf5786ff955658f21191fcdf34c7ad437d0d5f517ff83b4a97325cf). But all values are missing from the response.
    The response has "gas limit" instead of "gas used", and L1 gas details are missing

@elanh
Copy link
Collaborator

elanh commented Jul 30, 2022

hey @bmalepaty these types of questions are better for discord, feel free to join the alchemy discord here: alchemy.com/discord.

It also looks like you are referencing the response from your initial message (not the actual response from your second request here.

Can't seem to reproduce the results from the first request, however, if you re-post your question in discord someone should be able to help resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants