# trace_block

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

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

Returns traces created at a given block.

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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| blockIdentifier | string | Yes | Block identifier as a hex string block number or one of the tags: "earliest", "latest", "pending", "safe", or "finalized".  |

## Result

**Block Traces** (object): An object containing block trace details.

## Example

### Request

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

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "jsonrpc": "2.0",
    "id": 0,
    "result": {
      "output": "",
      "stateDiff": "",
      "trace": [
        {
          "name": "trace item",
          "value": {
            "action": {
              "callType": "call",
              "from": "0xaa7b131dc60b80d3cf5e59b5a21a666aa039c951",
              "gas": "0x0",
              "input": "0x",
              "to": "0xd40aba8166a212d6892125f079c33e6f5ca19814",
              "value": "0x4768d7effc3fbe"
            },
            "error": "",
            "subtraces": "0",
            "traceAddress": [],
            "type": "call"
          }
        }
      ],
      "vmTrace": ""
    }
  },
  "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_block",
  "params": [
    "0x2ed119"
  ]
}'
```

### JavaScript

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

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

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

```


## OpenRPC Method Specification

```yaml
name: trace_block
description: Returns traces created at a given block.
params:
  - name: blockIdentifier
    required: true
    description: |
      Block identifier as a hex string block number or one of the tags: "earliest", "latest", "pending", "safe", or "finalized".
    schema:
      type: string
      default: latest
result:
  name: Block Traces
  description: An object containing block trace details.
  schema:
    type: object
    properties:
      output:
        type: string
      stateDiff:
        type: string
      trace:
        type: array
        description: Array of trace objects.
        items:
          type: object
          properties:
            action:
              type: object
              description: Trace action details.
              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
            error:
              type: string
            subtraces:
              type: string
            traceAddress:
              type: array
              items:
                type: string
            type:
              type: string
      vmTrace:
        type: string
examples:
  - name: trace_block example
    params:
      - name: blockIdentifier
        value: '0x2ed119'
    result:
      name: trace_block response
      value:
        jsonrpc: '2.0'
        id: 0
        result:
          output: ''
          stateDiff: ''
          trace:
            - name: trace item
              value:
                action:
                  callType: call
                  from: '0xaa7b131dc60b80d3cf5e59b5a21a666aa039c951'
                  gas: '0x0'
                  input: 0x
                  to: '0xd40aba8166a212d6892125f079c33e6f5ca19814'
                  value: '0x4768d7effc3fbe'
                error: ''
                subtraces: '0'
                traceAddress: []
                type: call
          vmTrace: ''
```
