Interface overview
Every JavaScript tracer has this structure:Core methods
step(log, db)
This method runs for each EVM opcode that executes. Put your main analysis logic here. Parameters:log: The current execution context, with methods such asgetPC(),op.toString(), andgetCost()db: The database interface to query state
result(ctx, db)
This method runs at the end of execution and returns your analysis results. Parameters:ctx: The execution context, withgasUsedand transaction informationdb: The database interface for final queries
Advanced tracer examples
State change tracker
Track every state change in detail:DeFi transaction analysis
Analyze complex DeFi transactions with multiple contract interactions:Security analysis tracer
Detect suspicious patterns and potential vulnerabilities:Gas optimization tracer
Identify expensive operations for gas optimization:Performance optimization
Memory-efficient patterns
Selective operation tracking
Configuration options
Basic configuration
Production settings
Practical integration examples
Smart contract debugger
DeFi analytics dashboard
Best practices
- Start simple: Begin with basic tracers before you add complexity.
- Limit data collection: Collect only the information that you need.
- Use efficient data structures: Prefer counters to arrays when possible.
- Set appropriate timeouts: Balance thoroughness with performance.
- Test incrementally: Validate tracers on simple transactions first.
- Handle errors gracefully: Include error handling in your tracers.
Common use cases
Gas profiling
Event extraction
If you have issues with JavaScript tracers, see the Troubleshooting guide for common solutions and debugging tips.