This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
debug Methods
The debug namespace provides 5 debugging and development methods for transaction tracing and block analysis.
Debug methods are not part of the standard JSON-RPC spec and may not be available on all nodes. They are typically only enabled on development and testing nodes.
import * as Address from '@tevm/voltaire/Address';import * as Hex from '@tevm/voltaire/Hex';// Trace a call before submittingconst trace = await provider.debug_traceCall({ from: Address('0x742d35...'), to: Address('0xcontract...'), data: Hex('0xa9059cbb...') // transfer(address,uint256)}, 'latest', { tracer: 'callTracer'});if (!trace.error) { // Inspect internal calls before submitting transaction console.log('Will make calls:', trace.result.calls);}
// Get raw block bytesconst rawBlock = await provider.debug_getRawBlock('latest');if (!rawBlock.error) { console.log('RLP-encoded block:', rawBlock.result); // Can decode with RLP module}
import { Keccak256 } from '@tevm/voltaire/Keccak256';async function debugFailedTx(txHash: Keccak256.Keccak256Hash) { // Get transaction receipt const receipt = await provider.eth_getTransactionReceipt(txHash); if (!receipt.error && receipt.result.status === '0x0') { // Transaction reverted, trace it const trace = await provider.debug_traceTransaction(txHash, { tracer: 'callTracer' }); if (!trace.error) { console.log('Revert reason:', trace.result.error); console.log('Failed at:', trace.result.calls); } }}
Analyze Gas Usage
async function analyzeGas(txHash: Keccak256.Keccak256Hash) { const trace = await provider.debug_traceTransaction(txHash, { tracer: 'callTracer' }); if (!trace.error) { const result = trace.result; console.log('Total gas:', result.gasUsed); // Show gas for each call result.calls?.forEach(call => { console.log(`${call.type} to ${call.to}: ${call.gasUsed} gas`); }); }}
Test Before Sending
async function testTransaction(params: CallParams) { // Trace the call first const trace = await provider.debug_traceCall(params, 'latest', { tracer: 'callTracer' }); if (!trace.error) { if (trace.result.error) { console.error('Transaction would fail:', trace.result.error); return false; } console.log('Transaction would succeed'); console.log('Gas estimate:', trace.result.gasUsed); return true; } return false;}
Compare State Changes
async function compareStateChanges(txHash: Keccak256.Keccak256Hash) { // Get pre-state const preTrace = await provider.debug_traceTransaction(txHash, { tracer: 'prestateTracer' }); if (!preTrace.error) { const preState = preTrace.result; // Get transaction receipt for post-state const receipt = await provider.eth_getTransactionReceipt(txHash); console.log('Accounts modified:', Object.keys(preState)); }}
Node Requirements
Debug methods require specific node configuration:Geth: