# trace_get

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

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

Returns the trace at a given position for a transaction.

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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| transactionHash | string | Yes | Transaction hash. |
| traceIndexes | string[] | Yes | Array of trace index positions (in hex) to retrieve from the transaction.  |

## Result

**Trace Object** (object): Returns the trace object corresponding to the provided index(es).

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "trace_get",
  "params": [
    "0x17104ac9d3312d8c136b7f44d4b8b47852618065ebfa534bd2d3b5ef218ca1f3",
    [
      "0x0"
    ]
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "jsonrpc": "2.0",
    "id": 0,
    "result": {
      "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_get",
  "params": [
    "0x17104ac9d3312d8c136b7f44d4b8b47852618065ebfa534bd2d3b5ef218ca1f3",
    [
      "0x0"
    ]
  ]
}'
```

### JavaScript

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

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

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

```


## OpenRPC Method Specification

```yaml
name: trace_get
description: Returns the trace at a given position for a transaction.
params:
  - name: transactionHash
    required: true
    description: Transaction hash.
    schema:
      title: 32 byte hex value (any case)
      type: string
      pattern: ^0[xX][0-9A-Fa-f]{64}$
  - name: traceIndexes
    required: true
    description: |
      Array of trace index positions (in hex) to retrieve from the transaction.
    schema:
      type: array
      items:
        title: hex encoded unsigned integer (any case)
        type: string
        pattern: ^0[xX]([1-9A-Fa-f]+[0-9A-Fa-f]*|0)$
result:
  name: Trace Object
  description: Returns the trace object corresponding to the provided index(es).
  schema:
    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_get example
    params:
      - name: transactionHash
        value: '0x17104ac9d3312d8c136b7f44d4b8b47852618065ebfa534bd2d3b5ef218ca1f3'
      - name: traceIndexes
        value:
          - '0x0'
    result:
      name: trace_get response
      value:
        jsonrpc: '2.0'
        id: 0
        result:
          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
```
