Premiers pas avec TheRPC
Ethereum/Trace API/trace_replayTransaction

trace_replayTransaction

The trace_replayTransaction method allows you to replay a transaction and retrieve a variety of trace information including execution trace, VM trace, and state changes. This method provides more detailed information than trace_transaction by showing how the transaction changed the state.

Use Cases

  • Debugging complex transactions with state changes
  • Analyzing gas consumption for optimization
  • Tracing internal calls between contracts
  • Understanding how storage was modified by a transaction
  • Verifying the execution of complex logic flows
  • Security auditing with full state transition detail
  • Analyzing revert reasons with detailed context
  • Investigating memory and storage access patterns
  • Validating contract behavior as part of audit reviews
  • Optimizing contract code based on execution patterns

Method Details

This method replays a transaction and returns detailed trace information including VM trace and state differences.

Paramètres:

The hash of the transaction to replay

Array of trace types to include in the response

Retours:

Result object with trace information

Output data from the transaction

State differences caused by the transaction (if requested)

State changes for an address

Array of trace objects for all operations in the transaction

Details about the call action

Type of call (call, delegatecall, etc.)

Sender address

Gas provided for the call (hex)

Input data for the call (hex)

Recipient address

Value transferred in wei (hex)

Result of the call

Amount of gas used (hex)

Output data from the call (hex)

Number of subtraces

Address path of trace location in the call tree

Type of operation (call, create, suicide)

Virtual machine execution trace (if requested)

EVM bytecode being executed

Array of executed operations

Gas cost of the operation

Execution result of the operation

Program counter

Information about call sub-execution

Response Example

{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"output": "0x0000000000000000000000000000000000000000000000000000000000000001",
		"stateDiff": {
			"0x1234567890123456789012345678901234567890": {
				"balance": {
					"*": {
						"from": "0x100",
						"to": "0x110"
					}
				},
				"code": "=",
				"nonce": {
					"*": {
						"from": "0x10",
						"to": "0x11"
					}
				},
				"storage": {
					"0x0000000000000000000000000000000000000000000000000000000000000001": {
						"*": {
							"from": "0x0000000000000000000000000000000000000000000000000000000000000000",
							"to": "0x0000000000000000000000000000000000000000000000000000000000000001"
						}
					}
				}
			}
		},
		"trace": [
			{
				"action": {
					"callType": "call",
					"from": "0x83806d539d4ea1c140489a06660319c9a303f874",
					"gas": "0x1a1f8",
					"input": "0x",
					"to": "0x1c39ba39e4735cb65978d4db400ddd70a72dc750",
					"value": "0x7a16c911b4d00000"
				},
				"result": {
					"gasUsed": "0x2982",
					"output": "0x"
				},
				"subtraces": 2,
				"traceAddress": [],
				"type": "call"
			}
		],
		"vmTrace": {
			"code": "0x606060...",
			"ops": [
				{
					"cost": 3,
					"ex": {
						"mem": null,
						"push": ["0x60"],
						"store": null,
						"used": 16723979
					},
					"pc": 0,
					"sub": null
				}
			]
		}
	}
}

Trace Types

The traceTypes parameter accepts an array of the following values:

  • trace: The basic trace of transaction execution
  • vmTrace: A detailed trace of the EVM execution
  • stateDiff: State changes resulting from the transaction

You can request any combination of these trace types.

State Diff Format

The state diff format uses the following symbols:

  • "=": No change in the value
  • "+": The value was created
  • "-": The value was deleted
  • "*": The value was modified, with "from" and "to" values

Important Notes

  • This method requires trace APIs to be enabled on the Ethereum node
  • Not all Ethereum clients support this method (primarily OpenEthereum/Nethermind)
  • The response can be very large, especially with vmTrace enabled
  • For simple trace information without state changes, use trace_transaction instead
  • The method is computationally intensive and may take time to complete
  • Historical transactions can only be traced if the node maintains archive data
  • Different traceTypes significantly affect response size and computation time
  • For debugging simpler transactions, trace_transaction may be sufficient
  • State diffs are particularly valuable for understanding storage changes
  • Transactions that revert will show state changes up to the revert point

See also

Aidez-nous à nous améliorer !
Partagez cette page et aidez-nous à créer un produit encore meilleur pour vous.