Skip to main content
Tempo API method that replays a specific transaction and returns detailed execution traces. This is useful for debugging transaction behavior with customizable trace options.

Parameters

  • transactionHash — the hash of the transaction to replay
  • traceTypes — array of trace types to include:
    • trace — basic execution trace
    • vmTrace — full VM execution trace
    • stateDiff — state changes

Response

  • result — trace result object:
    • output — return data from the transaction
    • trace — array of trace objects (if requested)
    • vmTrace — VM execution trace (if requested)
    • stateDiff — state differences (if requested)

trace_replayTransaction code examples

const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);

const replayTransaction = async (txHash) => {
    // Replay with all trace types
    const result = await provider.send("trace_replayTransaction", [
      txHash,
      ["trace", "stateDiff"]
    ]);

    console.log("Transaction Output:", result.output);
    console.log("Traces:", result.trace?.length || 0);

    if (result.trace) {
      for (const trace of result.trace) {
        const callType = trace.action.callType || trace.type;
        const to = trace.action.to || "Contract Creation";
        console.log(`  ${callType}: ${trace.action.from} -> ${to}`);
      }
    }

    if (result.stateDiff) {
      console.log("\nState changes:");
      for (const [address, diff] of Object.entries(result.stateDiff)) {
        console.log(`  ${address}:`);
        if (diff.balance) {
          console.log(`    Balance: ${diff.balance['*']?.from || 'new'} -> ${diff.balance['*']?.to || diff.balance['+']}`);
        }
      }
    }
  };

replayTransaction("0xb3e821e696897b02283b7b2d602941b1d3cb08448d3a204bab05955215fc2035");