Optimism - tx hash 0x0000000000000000000000000000000000000000000000000000000000000000
With Optimism, when using the method debug_traceBlockByHash
you may encounter a problem retrieving the expected transaction hash, where it returns as follows:
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
Request example:
curl --location 'https://api.tatum.io/v3/blockchain/node/optimism-mainnet/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"jsonrpc": "2.0",
"method": "debug_traceBlockByHash",
"params": [
"0xc2e5cad4cf8082512c3053e698997ff2fc9e85511ad011b46fea29cb2f99cb62",
{
"tracer": "callTracer",
"timeout": "90s"
}
],
"id": 1
}'
//Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"result": {
"from": "0x2bdf9249c350c68a43a9714c1b9153af54751b1c",
"gas": "0x7302c",
"gasUsed": "0x1e484",
"input": "0xc9807539000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000300000100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000001d7dce2992ebb035c4fdcc21979e9c93000052e60509040005010806070203000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000023db1d8400000000000000000000000000000000000000000000000000000000242cf77cd0000000000000000000000000000000000000000000000000000000243752b9900000000000000000000000000000000000000000000000000000002439877000000000000000000000000000000000000000000000000000000000244404fc000000000000000000000000000000000000000000000000000000002447d58c000000000000000000000000000000000000000000000000000000002447d58c000000000000000000000000000000000000000000000000000000002447d58c00000000000000000000000000000000000000000000000000000000244ac5d780000000000000000000000000000000000000000000000000000000244ac5d780000000000000000000000000000000000000000000000000000000000000004369cd0767a7b28bb3fe197cc276988fd4f772c9e5e7bb6c6f4a815caeb923b20beec6706e905653f642fca76316bc1a75fb65a559bf32adc2d47019f22a3c2968cb4b8212ae507cf258b68c0d79de47002761f9b6a1d4c9dc1d4bc4d01e96f58729cb5d032590a1855d82ffce621141e0c7ff7f277fdf7d01814de5931078541000000000000000000000000000000000000000000000000000000000000000446f8124d6817323e3716549e388ec4639599677a339ec27bb167aa0c8435c3963e610d272a815e6bffadbd037bb23c6ffbe97da25805d9b111eaca2fef7afeed4192843d2244e8820988a195aec6cdd3f3ac48fe27d169cced5413f49fd1f49b22c717039e255f96f9d36924921e306f506e95707cd9b89061b545a5b540dadf",
"output": "0x",
"time": "94.757804ms",
"to": "0xa6d25eebae9c841c44ad01c9176556a4c2189961",
"type": "CALL",
"value": "0x0"
}
}
]
}
Root Cause Analysis
Tatum runs op-geth
and l2-geth
instances on the Optimism network.
l2-geth
has the legacy (pre-bedrock) data.
When querying pre-Bedrock blocks using the debug_traceBlockByHash
method, the response does not include the txHash either through op-geth
or directly from l2-geth
.
However, transaction hashes can still be retrieved using the following methods and trace:
eth_getBlockByNumber
eth_getBlockByHash
debug_traceTransaction
Additional details
1. debug_traceBlockByHash
on op-geth
debug_traceBlockByHash
on op-geth
The following query does not return the txHash for pre-Bedrock blocks:
curl -s -S
--location $OP_GETH
--header 'Content-Type: application/json'
--data '{
"jsonrpc": "2.0",
"method": "debug_traceBlockByHash",
"params": [
"0xc2e5cad4cf8082512c3053e698997ff2fc9e85511ad011b46fea29cb2f99cb62",
{
"tracer": "callTracer",
"timeout": "90s"
}
],
"id": 1
}' | jq .
//Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"txHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"result": {
"from": "0x2bdf9249c350c68a43a9714c1b9153af54751b1c",
"gas": "0x7302c",
"gasUsed": "0x1e484",
"input": "...",
"output": "0x",
"time": "125.850629ms",
"to": "0xa6d25eebae9c841c44ad01c9176556a4c2189961",
"type": "CALL",
"value": "0x0"
}
}
]
}
2. debug_traceBlockByHash
on l2-geth
debug_traceBlockByHash
on l2-geth
Querying directly on l2-geth also returns the trace without the txHash:
curl -s -S
--location $L2_GETH
--header 'Content-Type: application/json'
--data '{
"jsonrpc": "2.0",
"method": "debug_traceBlockByHash",
"params": [
"0xc2e5cad4cf8082512c3053e698997ff2fc9e85511ad011b46fea29cb2f99cb62",
{
"tracer": "callTracer",
"timeout": "90s"
}
],
"id": 1
}' | jq .
//Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"result": {
"type": "CALL",
"from": "0x2bdf9249c350c68a43a9714c1b9153af54751b1c",
"to": "0xa6d25eebae9c841c44ad01c9176556a4c2189961",
"value": "0x0",
"gas": "0x7302c",
"gasUsed": "0x1e484",
"input": "...",
"output": "0x",
"time": "126.806103ms"
}
}
]
}
3. eth_getBlockByNumber
to Retrieve Transaction Hash
eth_getBlockByNumber
to Retrieve Transaction HashThe transaction hash can be retrieved using:
curl -s -S
--location $OP_GETH
--header 'Content-Type: application/json'
--data '{
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": [
"0x4EAF17",
true
],
"id": 1
}' | jq '.result.transactions[0].hash'
//Response:
"0x84a9762c0fa0abe2bbaf3e9b6917c2338f13f36bf806b0d99ebaa90e1c4c3f14"
4. Handling the retrieval of traces for pre-Bedrock blocks
You may use something like the following script; to first get the transaction hashes and then trace each transaction individually:
#!/bin/zsh
# Environment variable for API key
API_KEY=$YOUR_KEY
# Function to get block details by hash
get_block_details() {
local block_hash=$1
curl --silent --location "https://api.tatum.io/v3/blockchain/node/optimism-mainnet" \
--header "x-api-key: $API_KEY" \
--header "Content-Type: application/json"
--data "{
\"jsonrpc\": \"2.0\",
\"method\": \"eth_getBlockByHash\",
\"params\": [\"$block_hash\", true],
\"id\": 1
}" | jq -r '.result.transactions[].hash'
}
# Function to trace transaction by hash
trace_transaction() {
local tx_hash=$1
curl --silent --location "https://api.tatum.io/v3/blockchain/node/optimism-mainnet" \
--header "x-api-key: $API_KEY" \
--header "Content-Type: application/json" --data "{
\"jsonrpc\": \"2.0\",
\"method\": \"debug_traceTransaction\",
\"params\": [\"$tx_hash\", {\"tracer\": \"callTracer\", \"timeout\": \"90s\"}],
\"id\": 1
}" | jq .
}
# Block hash to query
block_hash="0xc2e5cad4cf8082512c3053e698997ff2fc9e85511ad011b46fea29cb2f99cb62"
# Get transaction hashes from the block
tx_hashes=$(get_block_details $block_hash)
# Trace each transaction
for tx_hash in $tx_hashes; do
echo "Tracing transaction: $tx_hash"
trace_transaction $tx_hash
done
Updated 3 months ago