debug_traceBlockByNumber - Base

Example code for the debug_traceBlockByNumber JSON-RPC method. Complete guide on how to use debug_traceBlockByNumber JSON-RPC in GetBlock Web3 documentation.

The debug_traceBlockByNumber method returns traces for all transactions in a block, identified by block number. This is useful for analyzing all activity within a specific block when you know the block number.

Parameters

Parameter
Type
Required
Description

blockNumber

string

Yes

Block number in hex, or "latest", "earliest", "pending"

traceOptions

object

No

Tracing options object

Trace Options

Field
Type
Description

tracer

string

Tracer type: "callTracer", "prestateTracer", or custom JS

tracerConfig

object

Configuration for the tracer

timeout

string

Timeout for the trace operation

Request

cURL
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "debug_traceBlockByNumber",
    "params": ["0x12d687f", {"tracer": "callTracer"}],
    "id": "getblock.io"
}'

Response

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

array

Array of transaction traces

Trace Object

Field
Type
Description

txHash

string

Transaction hash

result

object

Trace result object

Use Cases

  • Sequential Analysis: Analyze blocks in sequence by number

  • Historical Research: Trace historical block activity

  • Gas Analysis: Profile gas usage per block

  • Indexing: Build transaction traces for indexing

  • Monitoring: Track activity at specific block heights

Error Handling

Error Code
Message
Description

-32602

Invalid params

Invalid block number or options

-32603

Internal error

Trace execution failed

-32000

Block not found

Block does not exist

Web3 Integration

Last updated

Was this helpful?