# trace_transaction

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

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

Returns all traces of a given transaction.

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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| transactionHash | string | Yes | 32 Bytes - Hash of a transaction.  |

## Result

**Traces** (object[]): Returns an array of trace objects for the given transaction.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "trace_transaction",
  "params": [
    "0x8fc90a6c3ee3001cdcbbb685b4fbe67b1fa2bec575b15b0395fea5540d0901ae"
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "jsonrpc": "2.0",
    "id": 0,
    "result": [
      {
        "name": "trace item",
        "value": {
          "action": {
            "callType": "call",
            "from": "0x83806d539d4ea1c140489a06660319c9a303f874",
            "gas": "0x1a1f8",
            "input": "0x",
            "to": "0x1c39ba39e4735cb65978d4db400ddd70a72dc750",
            "value": "0x7a16c911b4d00000"
          },
          "blockHash": "0x7eb25504e4c202cf3d62fd585d3e238f592c780cca82dacb2ed3cb5b38883add",
          "blockNumber": 3068185,
          "result": {
            "gasUsed": "0x2982",
            "output": "0x"
          },
          "subtraces": 2,
          "traceAddress": [],
          "transactionHash": "0x17104ac9d3312d8c136b7f44d4b8b47852618065ebfa534bd2d3b5ef218ca1f3",
          "transactionPosition": 2,
          "type": "call"
        }
      },
      {
        "name": "trace item",
        "value": {
          "action": {
            "callType": "call",
            "from": "0x1c39ba39e4735cb65978d4db400ddd70a72dc750",
            "gas": "0x13e99",
            "input": "0x16c72721",
            "to": "0x2bd2326c993dfaef84f696526064ff22eba5b362",
            "value": "0x0"
          },
          "blockHash": "0x7eb25504e4c202cf3d62fd585d3e238f592c780cca82dacb2ed3cb5b38883add",
          "blockNumber": 3068185,
          "result": {
            "gasUsed": "0x183",
            "output": "0x0000000000000000000000000000000000000000000000000000000000000001"
          },
          "subtraces": 0,
          "traceAddress": [
            "0x0"
          ],
          "transactionHash": "0x17104ac9d3312d8c136b7f44d4b8b47852618065ebfa534bd2d3b5ef218ca1f3",
          "transactionPosition": 2,
          "type": "call"
        }
      }
    ]
  },
  "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_transaction",
  "params": [
    "0x8fc90a6c3ee3001cdcbbb685b4fbe67b1fa2bec575b15b0395fea5540d0901ae"
  ]
}'
```

### JavaScript

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

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_transaction",
    "params": ["0x8fc90a6c3ee3001cdcbbb685b4fbe67b1fa2bec575b15b0395fea5540d0901ae"]
}
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_transaction\",\n  \"params\": [\n    \"0x8fc90a6c3ee3001cdcbbb685b4fbe67b1fa2bec575b15b0395fea5540d0901ae\"\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_transaction\",\n  \"params\": [\n    \"0x8fc90a6c3ee3001cdcbbb685b4fbe67b1fa2bec575b15b0395fea5540d0901ae\"\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_transaction\",\n  \"params\": [\n    \"0x8fc90a6c3ee3001cdcbbb685b4fbe67b1fa2bec575b15b0395fea5540d0901ae\"\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: trace_transaction
description: Returns all traces of a given transaction.
params:
  - name: transactionHash
    required: true
    description: |
      32 Bytes - Hash of a transaction.
    schema:
      title: 32 byte hex value (any case)
      type: string
      pattern: ^0[xX][0-9A-Fa-f]{64}$
result:
  name: Traces
  description: Returns an array of trace objects for the given transaction.
  schema:
    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: 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
examples:
  - name: trace_transaction example
    params:
      - name: transactionHash
        value: '0x8fc90a6c3ee3001cdcbbb685b4fbe67b1fa2bec575b15b0395fea5540d0901ae'
    result:
      name: trace_transaction response
      value:
        jsonrpc: '2.0'
        id: 0
        result:
          - name: trace item
            value:
              action:
                callType: call
                from: '0x83806d539d4ea1c140489a06660319c9a303f874'
                gas: '0x1a1f8'
                input: 0x
                to: '0x1c39ba39e4735cb65978d4db400ddd70a72dc750'
                value: '0x7a16c911b4d00000'
              blockHash: '0x7eb25504e4c202cf3d62fd585d3e238f592c780cca82dacb2ed3cb5b38883add'
              blockNumber: 3068185
              result:
                gasUsed: '0x2982'
                output: 0x
              subtraces: 2
              traceAddress: []
              transactionHash: '0x17104ac9d3312d8c136b7f44d4b8b47852618065ebfa534bd2d3b5ef218ca1f3'
              transactionPosition: 2
              type: call
          - name: trace item
            value:
              action:
                callType: call
                from: '0x1c39ba39e4735cb65978d4db400ddd70a72dc750'
                gas: '0x13e99'
                input: '0x16c72721'
                to: '0x2bd2326c993dfaef84f696526064ff22eba5b362'
                value: '0x0'
              blockHash: '0x7eb25504e4c202cf3d62fd585d3e238f592c780cca82dacb2ed3cb5b38883add'
              blockNumber: 3068185
              result:
                gasUsed: '0x183'
                output: '0x0000000000000000000000000000000000000000000000000000000000000001'
              subtraces: 0
              traceAddress:
                - '0x0'
              transactionHash: '0x17104ac9d3312d8c136b7f44d4b8b47852618065ebfa534bd2d3b5ef218ca1f3'
              transactionPosition: 2
              type: call
```
