# trace_rawTransaction

> 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-raw-transaction

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| rawTransaction | string | Yes | Raw transaction data. |
| traceTypes | enum[] | Yes | Array of trace types to return. Valid values include "trace" and "stateDiff".  |

## Result

**Block Traces** (object): Returns the traces from the raw transaction call.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "trace_rawTransaction",
  "params": [
    "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
    [
      "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": "0xaa7b131dc60b80d3cf5e59b5a21a666aa039c951",
              "gas": "0x0",
              "input": "0x",
              "to": "0xd40aba8166a212d6892125f079c33e6f5ca19814",
              "value": "0x4768d7effc3fbe"
            },
            "blockHash": "0x7eb25504e4c202cf3d62fd585d3e238f592c780cca82dacb2ed3cb5b38883add",
            "blockNumber": 3068185,
            "result": {
              "gasUsed": "0x0",
              "output": "0x"
            },
            "subtraces": "0",
            "traceAddress": [],
            "transactionHash": "0x07da28d752aba3b9dd7060005e554719c6205c8a3aea358599fc9b245c52f1f6",
            "transactionPosition": 0,
            "type": "call"
          }
        },
        {
          "name": "trace item",
          "value": {
            "action": {
              "callType": "call",
              "from": "0x4f11ba23bb526c0486d83c6a8f18f632f3fc172a",
              "gas": "0x0",
              "input": "0x",
              "to": "0x7ed1e469fcb3ee19c0366d829e291451be638e59",
              "value": "0x446cde325fbfbe"
            },
            "blockHash": "0x7eb25504e4c202cf3d62fd585d3e238f592c780cca82dacb2ed3cb5b38883add",
            "blockNumber": 3068185,
            "result": {
              "gasUsed": "0x0",
              "output": "0x"
            },
            "subtraces": "0",
            "traceAddress": [],
            "transactionHash": "0x056f11efb5da4ff7cf8523cfcef08393e5dd2ff3ab3223e4324426d285d7ae92",
            "transactionPosition": 1,
            "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_rawTransaction",
  "params": [
    "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
    [
      "trace"
    ]
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'trace_rawTransaction',
    params: [
      '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675',
      ['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_rawTransaction",
    "params": ["0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675", ["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_rawTransaction\",\n  \"params\": [\n    \"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675\",\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_rawTransaction\",\n  \"params\": [\n    \"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675\",\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_rawTransaction\",\n  \"params\": [\n    \"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675\",\n    [\n      \"trace\"\n    ]\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: trace_rawTransaction
description: Traces a call to eth_sendRawTransaction without executing it, returning the traces.
params:
  - name: rawTransaction
    required: true
    description: Raw transaction data.
    schema:
      title: hex encoded bytes (any case)
      type: string
      pattern: ^0x[0-9a-fA-F]*$
  - 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: Block Traces
  description: Returns the traces from the raw transaction call.
  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
            blockHash:
              title: 32 byte hex value (any case)
              type: string
              pattern: ^0[xX][0-9A-Fa-f]{64}$
            blockNumber:
              type: integer
            result:
              type: object
              properties:
                gasUsed:
                  type: string
                output:
                  type: string
            subtraces:
              type: string
            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_rawTransaction example
    params:
      - name: rawTransaction
        value: '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'
      - name: traceTypes
        value:
          - trace
    result:
      name: trace_rawTransaction response
      value:
        jsonrpc: '2.0'
        id: 0
        result:
          output: 0x
          stateDiff: null
          trace:
            - name: trace item
              value:
                action:
                  callType: call
                  from: '0xaa7b131dc60b80d3cf5e59b5a21a666aa039c951'
                  gas: '0x0'
                  input: 0x
                  to: '0xd40aba8166a212d6892125f079c33e6f5ca19814'
                  value: '0x4768d7effc3fbe'
                blockHash: '0x7eb25504e4c202cf3d62fd585d3e238f592c780cca82dacb2ed3cb5b38883add'
                blockNumber: 3068185
                result:
                  gasUsed: '0x0'
                  output: 0x
                subtraces: '0'
                traceAddress: []
                transactionHash: '0x07da28d752aba3b9dd7060005e554719c6205c8a3aea358599fc9b245c52f1f6'
                transactionPosition: 0
                type: call
            - name: trace item
              value:
                action:
                  callType: call
                  from: '0x4f11ba23bb526c0486d83c6a8f18f632f3fc172a'
                  gas: '0x0'
                  input: 0x
                  to: '0x7ed1e469fcb3ee19c0366d829e291451be638e59'
                  value: '0x446cde325fbfbe'
                blockHash: '0x7eb25504e4c202cf3d62fd585d3e238f592c780cca82dacb2ed3cb5b38883add'
                blockNumber: 3068185
                result:
                  gasUsed: '0x0'
                  output: 0x
                subtraces: '0'
                traceAddress: []
                transactionHash: '0x056f11efb5da4ff7cf8523cfcef08393e5dd2ff3ab3223e4324426d285d7ae92'
                transactionPosition: 1
                type: call
          vmTrace: null
```
