The debug namespace provides powerful introspection capabilities that can be resource-intensive. These methods should be used carefully and are typically only available on trusted nodes with debugging enabled.
Overview
The debug namespace offers methods for debugging transactions, tracing execution, inspecting state, and diagnosing blockchain issues.
Transaction Tracing
debug_traceTransaction
Returns a detailed trace of a transaction’s execution.
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"debug_traceTransaction","params":["0x1234...",{}],"id":1}' \
http://localhost:8545
Transaction hash (32 bytes, hex encoded)
Trace configuration options Tracer type: “callTracer”, “prestateTracer”, or custom JavaScript
Timeout in seconds (default: “5s”)
Disable storage capture (default: false)
Disable memory capture (default: false)
Disable stack capture (default: false)
Execution trace with opcode-level details
Example Response:
{
"jsonrpc" : "2.0" ,
"id" : 1 ,
"result" : {
"gas" : 21000 ,
"failed" : false ,
"returnValue" : "" ,
"structLogs" : [
{
"pc" : 0 ,
"op" : "PUSH1" ,
"gas" : 79000 ,
"gasCost" : 3 ,
"depth" : 1 ,
"stack" : [],
"memory" : []
}
]
}
}
debug_traceBlockByNumber
Traces all transactions in a block by block number.
Block number (hex) or “latest”
Trace configuration (same as debug_traceTransaction)
Array of transaction traces for all transactions in the block
debug_traceBlockByHash
Traces all transactions in a block by block hash.
Block hash (32 bytes, hex encoded)
Trace configuration (same as debug_traceTransaction)
debug_traceBlock
Traces all transactions in a raw block.
RLP-encoded block data (hex)
Block Inspection
debug_dumpBlock
Returns the state of all accounts at a given block.
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"debug_dumpBlock","params":["latest"],"id":1}' \
http://localhost:8545
Block number (hex) or “latest”, “earliest”, “pending”
State dump containing all account data Map of address to account state
debug_printBlock
Returns a human-readable representation of a block.
Pretty-printed block information
debug_getBlockRlp
Returns RLP-encoded block data.
State Inspection
debug_storageRangeAt
Returns storage entries for a contract at a specific transaction.
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"debug_storageRangeAt","params":["0xblockHash",0,"0xcontractAddress","0x0",100],"id":1}' \
http://localhost:8545
Transaction index in block
Starting storage key (hex)
Maximum number of entries to return
Storage range result Map of storage keys to values
Next key for pagination (null if complete)
debug_preimage
Returns the preimage of a hash stored in the database.
Preimage data (hex) or null if not found
debug_getModifiedAccountsByNumber
Returns accounts modified between two blocks.
Start block number (decimal)
End block number (decimal, optional)
Array of addresses that were modified
debug_getModifiedAccountsByHash
Returns accounts modified between two blocks (by hash).
End block hash (optional)
Bad Blocks
debug_getBadBlocks
Returns a list of recently rejected bad blocks.
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"debug_getBadBlocks","params":[],"id":1}' \
http://localhost:8545
Array of bad block objects with rejection reasons
Chain Management
debug_setHead
Rewinds the blockchain to a specific block number.
This is a destructive operation that removes blocks from the chain. Use with extreme caution.
Block number to rewind to (hex)
debug_seedHash
Returns the seed hash used for PoW at a given block.
Database Operations
debug_chaindbProperty
Returns LevelDB properties.
Property name (e.g., “leveldb.stats”)
debug_chaindbCompact
Triggers a database compaction.
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"debug_chaindbCompact","params":[],"id":1}' \
http://localhost:8545
Database compaction can take significant time and resources. Run during low-traffic periods.
Usage Examples
JavaScript - Transaction Tracing
const Web3 = require ( 'web3' );
const web3 = new Web3 ( 'http://localhost:8545' );
// Trace a transaction
async function traceTransaction ( txHash ) {
const trace = await web3 . currentProvider . send ({
jsonrpc: '2.0' ,
method: 'debug_traceTransaction' ,
params: [ txHash , {
tracer: 'callTracer' ,
timeout: '10s'
}],
id: 1
});
console . log ( 'Gas used:' , trace . result . gas );
console . log ( 'Failed:' , trace . result . failed );
return trace . result ;
}
// Usage
traceTransaction ( '0x1234...' );
Python - State Inspection
from web3 import Web3
w3 = Web3(Web3.HTTPProvider( 'http://localhost:8545' ))
# Get modified accounts
def get_modified_accounts ( start_block , end_block ):
result = w3.provider.make_request(
'debug_getModifiedAccountsByNumber' ,
[start_block, end_block]
)
return result[ 'result' ]
# Get storage range
def get_storage_range ( block_hash , tx_index , contract_addr ):
result = w3.provider.make_request(
'debug_storageRangeAt' ,
[block_hash, tx_index, contract_addr, '0x0' , 100 ]
)
return result[ 'result' ]
Call Tracer Example
// Trace with call tracer for high-level view
const callTrace = await web3 . currentProvider . send ({
jsonrpc: '2.0' ,
method: 'debug_traceTransaction' ,
params: [ '0xtxHash' , {
tracer: 'callTracer'
}],
id: 1
});
// Result shows call hierarchy
console . log ( JSON . stringify ( callTrace . result , null , 2 ));
/*
{
"type": "CALL",
"from": "0x...",
"to": "0x...",
"value": "0x0",
"gas": "0x...",
"gasUsed": "0x...",
"input": "0x...",
"output": "0x...",
"calls": [
{
"type": "DELEGATECALL",
"from": "0x...",
"to": "0x..."
}
]
}
*/
Resource Usage Debug methods can be extremely resource-intensive:
debug_traceTransaction: Can take seconds to minutes for complex transactions
debug_traceBlockByNumber: Multiplies trace time by number of transactions
debug_dumpBlock: Can return very large responses for blocks with many accounts
Storage operations: May require scanning large portions of the state trie
Best Practices
Use timeouts : Always set reasonable timeouts for trace operations
Disable unnecessary data : Use disableStorage, disableMemory, disableStack to reduce overhead
Limit scope : Trace specific transactions rather than entire blocks when possible
Cache results : Store trace results to avoid recomputation
Use dedicated nodes : Run debug operations on separate nodes from production RPC
Enabling Debug APIs
To enable debug APIs on a Viction node:
tomo --http --http.api "eth,net,web3,debug" \
--http.corsdomain "*" \
--http.vhosts "*"
Never expose debug APIs on public endpoints. They can:
Consume significant resources
Reveal sensitive state information
Be used for DoS attacks
Impact node performance
Common Use Cases
Transaction Debugging Trace failed transactions to identify revert reasons and execution flow
Gas Optimization Analyze opcode execution to optimize gas usage in smart contracts
State Analysis Inspect contract storage and account states at specific blocks
Security Auditing Trace contract interactions to verify security properties