# zone_getBeaconStateRoot

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

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

Returns the block hash and header state root of a beacon chain block that the node has followed. The values come from the node's own records of the beacon chain, not from its beacon source.

Only recent beacon heights are available: the node keeps roughly the last 48,000 beacon blocks. Requesting an older height returns an "invalid params" error whose `data.firstRetained` is the oldest height still held. Requesting a height above the followed history returns a `-32001` error.

Reference: https://www.alchemy.com/docs/chains/zero/zero-api-endpoints/zone-get-beacon-state-root

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Beacon height | string | Yes | The beacon chain height, as a hex-encoded quantity. |

## Result

**Beacon state root** (object): The block hash and state root of the requested beacon block.

## Example

### Request

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

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "beaconHeight": "0xd8a75",
    "blockHash": "0x4721e36726edc91fcb858efcd86e95645933d4a1151b505e91fcfb6712b5f513",
    "stateRoot": "0x6f8b9656134e8bfb710bcc163ba9504a52b77febe4b02bc35670bbb134eeafe8"
  },
  "id": 1
}
```

## Code Examples

### cURL

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

### JavaScript

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

fetch('https://zerointerop-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://zerointerop-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "zone_getBeaconStateRoot",
    "params": ["0xd8a75"]
}
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://zerointerop-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"zone_getBeaconStateRoot\",\n  \"params\": [\n    \"0xd8a75\"\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://zerointerop-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"zone_getBeaconStateRoot\",\n  \"params\": [\n    \"0xd8a75\"\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://zerointerop-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\": \"zone_getBeaconStateRoot\",\n  \"params\": [\n    \"0xd8a75\"\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: zone_getBeaconStateRoot
summary: Returns the block hash and state root of a followed beacon block.
description: |-
  Returns the block hash and header state root of a beacon chain block that the node has followed. The values come from the node's own records of the beacon chain, not from its beacon source.

  Only recent beacon heights are available: the node keeps roughly the last 48,000 beacon blocks. Requesting an older height returns an "invalid params" error whose `data.firstRetained` is the oldest height still held. Requesting a height above the followed history returns a `-32001` error.
x-compute-units: 20
params:
  - name: Beacon height
    required: true
    description: The beacon chain height, as a hex-encoded quantity.
    schema:
      title: hex encoded unsigned integer
      type: string
      pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
result:
  name: Beacon state root
  description: The block hash and state root of the requested beacon block.
  schema:
    title: Beacon state root
    type: object
    required:
      - beaconHeight
      - blockHash
      - stateRoot
    properties:
      beaconHeight:
        title: Beacon height
        type: string
        pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        description: The beacon chain height.
      blockHash:
        title: Block hash
        type: string
        pattern: ^0x[0-9a-f]{64}$
        description: The hash of the beacon block.
      stateRoot:
        title: State root
        type: string
        pattern: ^0x[0-9a-f]{64}$
        description: The state root from the beacon block header.
examples:
  - name: zone_getBeaconStateRoot example
    params:
      - name: Beacon height
        value: '0xd8a75'
    result:
      name: Beacon state root
      value:
        beaconHeight: '0xd8a75'
        blockHash: '0x4721e36726edc91fcb858efcd86e95645933d4a1151b505e91fcfb6712b5f513'
        stateRoot: '0x6f8b9656134e8bfb710bcc163ba9504a52b77febe4b02bc35670bbb134eeafe8'
errors:
  - code: -32001
    message: The beacon height is above the followed history
  - code: -32602
    message: The beacon height is no longer held
  - code: -32000
    message: Read failure or timeout
```
