Skip to main content
JavaScript tracers let you create custom debugging logic to analyze EVM transactions on Sei. You can use them for more complex analysis than the built-in tracers support.

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 as getPC(), op.toString(), and getCost()
  • db: The database interface to query state
Gas cost: Varies by tracer complexity

result(ctx, db)

This method runs at the end of execution and returns your analysis results. Parameters:
  • ctx: The execution context, with gasUsed and transaction information
  • db: 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

Optimize your tracer code, and use timeouts in production. JavaScript tracers can slow down tracing significantly.

Memory-efficient patterns

Selective operation tracking

Configuration options

Basic configuration

Production settings

Practical integration examples

Smart contract debugger

DeFi analytics dashboard

Best practices

  1. Start simple: Begin with basic tracers before you add complexity.
  2. Limit data collection: Collect only the information that you need.
  3. Use efficient data structures: Prefer counters to arrays when possible.
  4. Set appropriate timeouts: Balance thoroughness with performance.
  5. Test incrementally: Validate tracers on simple transactions first.
  6. 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.