# trace_replayTransaction

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://eth-mainnet.g.alchemy.com/v2/{apiKey}

Traces a call to eth_sendRawTransaction without executing it, returning the traces.

Reference: https://www.alchemy.com/docs/node/trace-api/trace-api-endpoints/trace-replay-transaction

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| transactionHash | string | Yes | Transaction hash of the raw transaction to be replayed.  |
| traceTypes | enum[] | Yes | Array of trace types to return. Valid values include "trace" and "stateDiff".  |

## Result

**Trace Replay Result** (object): Returns the trace result from replaying the transaction.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "trace_replayTransaction",
  "params": [
    "0x02d4a872e096445e80d05276ee756cefef7f3b376bcec14246469c0cd97dad8f",
    [
      "trace"
    ]
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "jsonrpc": "2.0",
    "id": 0,
    "result": {
      "output": "0x",
      "stateDiff": null,
      "trace": [
        {
          "name": "trace item",
          "value": {
            "action": {
              "callType": "call",
              "from": "0x6f1fb6efdf50f34bfa3f2bc0e5576edd71631638",
              "gas": "0x1dcd11f8",
              "input": "0xa67a6a45000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000",
              "to": "0x1e0447b19bb6ecfdae1e4ae1694b0c3659614e4e",
              "value": "0x0"
            },
            "result": {
              "gasUsed": "0x0",
              "output": "0x"
            },
            "subtraces": 0,
            "traceAddress": [],
            "transactionHash": "0x02d4a872e096445e80d05276ee756cefef7f3b376bcec14246469c0cd97dad8f",
            "transactionPosition": 0,
            "type": "call"
          }
        }
      ],
      "vmTrace": null
    }
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://eth-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "trace_replayTransaction",
  "params": [
    "0x02d4a872e096445e80d05276ee756cefef7f3b376bcec14246469c0cd97dad8f",
    [
      "trace"
    ]
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'trace_replayTransaction',
    params: [
      '0x02d4a872e096445e80d05276ee756cefef7f3b376bcec14246469c0cd97dad8f',
      ['trace']
    ]
  })
};

fetch('https://eth-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://eth-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "trace_replayTransaction",
    "params": ["0x02d4a872e096445e80d05276ee756cefef7f3b376bcec14246469c0cd97dad8f", ["trace"]]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://eth-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"trace_replayTransaction\",\n  \"params\": [\n    \"0x02d4a872e096445e80d05276ee756cefef7f3b376bcec14246469c0cd97dad8f\",\n    [\n      \"trace\"\n    ]\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://eth-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"trace_replayTransaction\",\n  \"params\": [\n    \"0x02d4a872e096445e80d05276ee756cefef7f3b376bcec14246469c0cd97dad8f\",\n    [\n      \"trace\"\n    ]\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://eth-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"trace_replayTransaction\",\n  \"params\": [\n    \"0x02d4a872e096445e80d05276ee756cefef7f3b376bcec14246469c0cd97dad8f\",\n    [\n      \"trace\"\n    ]\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: trace_replayTransaction
description: Traces a call to eth_sendRawTransaction without executing it, returning the traces.
params:
  - name: transactionHash
    required: true
    description: |
      Transaction hash of the raw transaction to be replayed.
    schema:
      title: 32 byte hex value (any case)
      type: string
      pattern: ^0[xX][0-9A-Fa-f]{64}$
  - name: traceTypes
    required: true
    description: |
      Array of trace types to return. Valid values include "trace" and "stateDiff".
    schema:
      type: array
      default:
        - trace
      items:
        type: string
        enum:
          - trace
          - stateDiff
result:
  name: Trace Replay Result
  description: Returns the trace result from replaying the transaction.
  schema:
    type: object
    properties:
      output:
        type: string
      stateDiff:
        type: string
        nullable: true
      trace:
        type: array
        items:
          type: object
          properties:
            action:
              type: object
              properties:
                callType:
                  type: string
                from:
                  title: hex encoded address
                  type: string
                  pattern: ^0x[0-9a-fA-F]{40}$
                gas:
                  type: string
                input:
                  type: string
                to:
                  title: hex encoded address
                  type: string
                  pattern: ^0x[0-9a-fA-F]{40}$
                value:
                  type: string
            result:
              type: object
              properties:
                gasUsed:
                  type: string
                output:
                  type: string
            subtraces:
              type: integer
            traceAddress:
              type: array
              items:
                type: string
            transactionHash:
              title: 32 byte hex value (any case)
              type: string
              pattern: ^0[xX][0-9A-Fa-f]{64}$
            transactionPosition:
              type: integer
            type:
              type: string
      vmTrace:
        type: string
        nullable: true
examples:
  - name: trace_replayTransaction example
    params:
      - name: transactionHash
        value: '0x02d4a872e096445e80d05276ee756cefef7f3b376bcec14246469c0cd97dad8f'
      - name: traceTypes
        value:
          - trace
    result:
      name: trace_replayTransaction response
      value:
        jsonrpc: '2.0'
        id: 0
        result:
          output: 0x
          stateDiff: null
          trace:
            - name: trace item
              value:
                action:
                  callType: call
                  from: '0x6f1fb6efdf50f34bfa3f2bc0e5576edd71631638'
                  gas: '0x1dcd11f8'
                  input: '0xa67a6a45000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000'
                  to: '0x1e0447b19bb6ecfdae1e4ae1694b0c3659614e4e'
                  value: '0x0'
                result:
                  gasUsed: '0x0'
                  output: 0x
                subtraces: 0
                traceAddress: []
                transactionHash: '0x02d4a872e096445e80d05276ee756cefef7f3b376bcec14246469c0cd97dad8f'
                transactionPosition: 0
                type: call
          vmTrace: null
```
