> ## Documentation Index
> Fetch the complete documentation index at: https://seilabs-docs-evm-cookbook.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Troubleshooting Guide

> Comprehensive troubleshooting guide for EVM transaction tracing on Sei. Resolve common issues with timeouts, memory limits, JavaScript errors, and performance optimization.

This guide covers common issues with EVM transaction tracing on Sei and gives practical solutions for them.

## Common error categories

### 1. Timeout errors

**Error**: `execution timeout`

**Cause**: The tracer execution exceeded the configured timeout.

**Solutions**:

```json theme={null}
{
  "tracerConfig": {
    "timeout": "120s" // Increase timeout for complex traces
  }
}
```

**Best practices**:

* Start with shorter timeouts (30s) for testing
* Increase the timeout gradually, based on transaction complexity
* Use built-in tracers when possible, because they are faster
* Optimize JavaScript tracer code for performance

### 2. Memory limit errors

**Error**: `out of memory` or `memory limit exceeded`

**Cause**: The tracer collected too much data or used memory inefficiently.

**Solutions**:

```json theme={null}
{
  "tracerConfig": {
    "enableMemory": false, // Disable memory tracing
    "enableStack": false, // Disable stack tracing
    "enableStorage": false // Disable storage tracing
  }
}
```

**Memory-efficient tracer pattern**:

```javascript theme={null}
{
  "tracer": `{
    // Use counters instead of arrays
    summary: {
      totalGas: 0,
      operationCount: 0,
      expensiveOps: 0
    },

    step: function(log, db) {
      this.summary.totalGas += log.getCost();
      this.summary.operationCount++;

      // Only track expensive operations
      if (log.getCost() > 1000) {
        this.summary.expensiveOps++;
      }
    },

    result: function(ctx, db) {
      return this.summary; // Return summary, not raw data
    }
  }`
}
```

### 3. JavaScript tracer errors

**Error**: `SyntaxError` or `ReferenceError` in a JavaScript tracer

**Common issues**:

```javascript theme={null}
// ❌ Incorrect - Missing quotes
{
  "tracer": `{
    step: function(log, db) {
      var op = log.op.toString();
      if (op == SSTORE) { // Missing quotes around SSTORE
        // ...
      }
    }
  }`
}

// ✅ Correct - Proper quotes
{
  "tracer": `{
    step: function(log, db) {
      var op = log.op.toString();
      if (op == "SSTORE") { // Quoted properly
        // ...
      }
    }
  }`
}
```

**Debugging JavaScript tracers**:

```javascript theme={null}
{
  "tracer": `{
    errors: [],

    step: function(log, db) {
      try {
        // Your tracer logic here
        var op = log.op.toString();
        // ...
      } catch (e) {
        this.errors.push({
          error: e.toString(),
          pc: log.getPC(),
          op: log.op.toString()
        });
      }
    },

    result: function(ctx, db) {
      return {
        data: this.data,
        errors: this.errors // Check for errors
      };
    }
  }`
}
```

### 4. Network and connection issues

**Error**: `connection refused` or `network timeout`

**Solutions**:

```bash theme={null}
# Check if node is running
curl -X POST -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
  http://localhost:8545

# Test with different timeout
curl --connect-timeout 30 --max-time 120 \
  -X POST -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"debug_traceTransaction","params":["0x..."],"id":1}' \
  http://localhost:8545
```

### 5. Transaction not found

**Error**: `transaction not found`

**Debugging steps**:

```bash theme={null}
# 1. Verify transaction exists
curl -X POST -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0x..."],"id":1}' \
  http://localhost:8545

# 2. Check if transaction is in a finalized block
curl -X POST -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0x..."],"id":1}' \
  http://localhost:8545

# 3. Ensure node is fully synced
curl -X POST -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' \
  http://localhost:8545
```

## Performance optimization

### Tracer performance tips

1. **Limit data collection**:

```javascript theme={null}
{
  "tracer": `{
    data: [],
    maxEntries: 1000, // Limit data collection

    step: function(log, db) {
      if (this.data.length < this.maxEntries) {
        // Only collect limited data
        this.data.push({
          pc: log.getPC(),
          op: log.op.toString(),
          gas: log.getGas()
        });
      }
    }
  }`
}
```

2. **Use efficient data structures**:

```javascript theme={null}
// ❌ Inefficient - Object lookups
{
  "tracer": `{
    operations: {},

    step: function(log, db) {
      var op = log.op.toString();
      if (!this.operations[op]) {
        this.operations[op] = 0;
      }
      this.operations[op]++;
    }
  }`
}

// ✅ Efficient - Direct assignment
{
  "tracer": `{
    operations: {},

    step: function(log, db) {
      var op = log.op.toString();
      this.operations[op] = (this.operations[op] || 0) + 1;
    }
  }`
}
```

3. **Selective tracing**:

```javascript theme={null}
{
  "tracer": `{
    step: function(log, db) {
      var op = log.op.toString();

      // Only trace specific operations
      if (op == "SSTORE" || op == "SLOAD" || op == "CALL") {
        // Process only important operations
        this.processOperation(log, db);
      }
    }
  }`
}
```

### Node configuration for better performance

```toml theme={null}
# In your node configuration
[evm]
# Increase trace timeout
trace-timeout = "300s"

# Increase memory limits
trace-memory-limit = "1GB"

# Enable trace caching
trace-cache-size = 1000
```

## Debugging workflows

### 1. Failed transaction analysis

```bash theme={null}
#!/bin/bash

TX_HASH="0x..."

echo "1. Checking if transaction exists..."
curl -s -X POST -H "Content-Type: application/json" \
  --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionByHash\",\"params\":[\"$TX_HASH\"],\"id\":1}" \
  http://localhost:8545 | jq '.result'

echo "2. Getting transaction receipt..."
curl -s -X POST -H "Content-Type: application/json" \
  --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionReceipt\",\"params\":[\"$TX_HASH\"],\"id\":1}" \
  http://localhost:8545 | jq '.result.status'

echo "3. Tracing transaction..."
curl -s -X POST -H "Content-Type: application/json" \
  --data "{\"jsonrpc\":\"2.0\",\"method\":\"debug_traceTransaction\",\"params\":[\"$TX_HASH\",{\"tracer\":\"callTracer\"}],\"id\":1}" \
  http://localhost:8545 | jq '.result'
```

### 2. Gas optimization workflow

```javascript theme={null}
// Step 1: Identify expensive operations
const expensiveOpsTracer = `{
  expensive: [],
  threshold: 1000,
  
  step: function(log, db) {
    var cost = log.getCost();
    if (cost > this.threshold) {
      this.expensive.push({
        pc: log.getPC(),
        op: log.op.toString(),
        cost: cost
      });
    }
  },
  
  result: function(ctx, db) {
    this.expensive.sort((a, b) => b.cost - a.cost);
    return {
      totalExpensive: this.expensive.length,
      topExpensive: this.expensive.slice(0, 10)
    };
  }
}`;

// Step 2: Analyze storage operations
const storageTracer = `{
  storageOps: 0,
  storageGas: 0,
  
  step: function(log, db) {
    var op = log.op.toString();
    if (op == "SSTORE" || op == "SLOAD") {
      this.storageOps++;
      this.storageGas += log.getCost();
    }
  },
  
  result: function(ctx, db) {
    return {
      storageOperations: this.storageOps,
      storageGasCost: this.storageGas,
      averageCost: this.storageOps > 0 ? this.storageGas / this.storageOps : 0
    };
  }
}`;
```

## Error code reference

### Common HTTP error codes

| Code | Error | Solution |
| - | - | - |
| 400 | Bad Request | Check the JSON-RPC format and parameters |
| 404 | Not Found | Verify the transaction hash and node sync status |
| 500 | Internal Server Error | Check the node logs and resource limits |
| 503 | Service Unavailable | The node may be syncing or overloaded |

### Tracer-specific errors

| Error | Cause | Solution |
| - | - | - |
| `execution timeout` | The tracer took too long | Increase the timeout or optimize the tracer |
| `out of memory` | Too much data collected | Reduce data collection or disable memory tracing |
| `invalid tracer` | JavaScript syntax error | Validate the tracer syntax |
| `tracer not found` | The built-in tracer does not exist | Check the available tracers |

## Best practices summary

### ✅ Do's

* **Start simple**: Begin with built-in tracers before you write custom JavaScript.
* **Set timeouts**: Always configure appropriate timeouts.
* **Limit data**: Collect only the information that you need.
* **Test incrementally**: Test tracers on simple transactions first.
* **Monitor resources**: Watch memory and CPU usage.
* **Cache results**: Store expensive trace results when possible.

### ❌ Don'ts

* **Do not collect everything**: Avoid tracing all operations unnecessarily.
* **Do not ignore errors**: Always handle tracer errors gracefully.
* **Do not use complex logic**: Keep tracer step functions simple.
* **Do not forget timeouts**: Never run tracers without timeout limits.
* **Do not trace in production**: Avoid heavy tracing on production nodes.

## Getting help

If you have an issue that this guide does not cover:

1. **Check node logs**: Look for error messages in your Sei node logs.
2. **Verify the configuration**: Make sure that tracing is enabled on your node.
3. **Test connectivity**: Confirm that the RPC endpoints are accessible.
4. **Simplify tracers**: Try built-in tracers first.
5. **Community support**: Ask in the #dev-support channel of the [Sei Discord](https://discord.gg/sei).

<Info>When you report an issue, include your tracer code, the transaction hash, and any error messages that you receive. This helps the community help you.</Info>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.