# starknet_getStateUpdate

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

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

Get the information about the result of executing the requested block

Reference: https://www.alchemy.com/docs/chains/starknet/starknet-api-endpoints/starknet-get-state-update

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| block_id | object or enum | Yes | The hash of the requested block, or number (height) of the requested block, or a block tag  |

## Result

**result** (object): The information about the state update of the requested block

## Code Examples

### cURL

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

### JavaScript

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

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

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

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

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://starknet-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\": \"starknet_getStateUpdate\",\n  \"params\": [\n    {\n      \"block_hash\": \"string\"\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: starknet_getStateUpdate
description: Get the information about the result of executing the requested block
params:
  - name: block_id
    description: |
      The hash of the requested block, or number (height) of the requested block, or a block tag
    required: true
    schema:
      title: Block id
      description: Block hash, number or tag
      oneOf:
        - title: Block hash
          type: object
          required:
            - block_hash
          properties:
            block_hash:
              title: Block hash
              description: The hash identifying a block
              type: string
              pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
        - title: Block number
          type: object
          required:
            - block_number
          properties:
            block_number:
              title: Block number
              description: The block's number (its height)
              type: integer
              minimum: 0
        - title: Block tag
          description: A tag specifying a dynamic reference to a block
          type: string
          enum:
            - latest
            - pending
result:
  name: result
  description: The information about the state update of the requested block
  schema:
    title: Starknet get state update result
    oneOf:
      - title: State update
        type: object
        required:
          - state_diff
          - block_hash
          - old_root
          - new_root
        properties:
          block_hash:
            title: Block hash
            description: The hash identifying a block
            type: string
            pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
          old_root:
            title: Old root
            description: The previous global state root
            type: string
            pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
          new_root:
            title: New root
            description: The new global state root
            type: string
            pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
          state_diff:
            title: State diff
            description: The change in state applied in this block, given as a mapping of addresses to the new values and/or new contracts
            type: object
            required:
              - storage_diffs
              - deprecated_declared_classes
              - declared_classes
              - replaced_classes
              - deployed_contracts
              - nonces
            properties:
              storage_diffs:
                title: Storage diffs
                type: array
                items:
                  title: Contract storage diff item
                  type: object
                  required:
                    - address
                    - storage_entries
                  properties:
                    address:
                      title: Address
                      description: The contract address for which the storage changed
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    storage_entries:
                      title: Storage entries
                      description: The changes in the storage of the contract
                      type: array
                      items:
                        title: Storage diff item
                        type: object
                        properties:
                          key:
                            title: Key
                            description: The key of the changed value
                            type: string
                            pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                          value:
                            title: Value
                            description: The new value applied to the given address
                            type: string
                            pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              deprecated_declared_classes:
                title: Deprecated declared classes
                type: array
                items:
                  title: Field element
                  description: A field element. Represented by at most 63 hex digits
                  type: string
                  pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              declared_classes:
                title: Declared classes
                type: array
                items:
                  title: New classes
                  type: object
                  description: The declared class hash and compiled class hash
                  properties:
                    class_hash:
                      title: Class hash
                      description: The hash of the declared class
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    compiled_class_hash:
                      title: Compiled class hash
                      description: The Cairo assembly hash corresponding to the declared class
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              deployed_contracts:
                title: Deployed contracts
                type: array
                items:
                  title: Deployed contract item
                  type: object
                  required:
                    - address
                    - class_hash
                  properties:
                    address:
                      title: Address
                      description: The address of the contract
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    class_hash:
                      title: Class hash
                      description: The hash of the contract code
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              replaced_classes:
                title: Replaced classes
                type: array
                items:
                  title: Replaced class
                  type: object
                  description: The list of contracts whose class was replaced
                  properties:
                    contract_address:
                      title: Contract address
                      description: The address of the contract whose class was replaced
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    class_hash:
                      title: Class hash
                      description: The new class hash
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              nonces:
                title: Nonces
                type: array
                items:
                  title: Nonce update
                  type: object
                  description: The updated nonce per contract address
                  properties:
                    contract_address:
                      title: Contract address
                      description: The address of the contract
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    nonce:
                      title: Nonce
                      description: The nonce for the given address at the end of the block
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
      - title: Pending state update
        description: Pending state update
        type: object
        required:
          - old_root
          - state_diff
        additionalProperties: false
        properties:
          old_root:
            title: Old root
            description: The previous global state root
            type: string
            pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
          state_diff:
            title: State diff
            description: The change in state applied in this block, given as a mapping of addresses to the new values and/or new contracts
            type: object
            required:
              - storage_diffs
              - deprecated_declared_classes
              - declared_classes
              - replaced_classes
              - deployed_contracts
              - nonces
            properties:
              storage_diffs:
                title: Storage diffs
                type: array
                items:
                  title: Contract storage diff item
                  type: object
                  required:
                    - address
                    - storage_entries
                  properties:
                    address:
                      title: Address
                      description: The contract address for which the storage changed
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    storage_entries:
                      title: Storage entries
                      description: The changes in the storage of the contract
                      type: array
                      items:
                        title: Storage diff item
                        type: object
                        properties:
                          key:
                            title: Key
                            description: The key of the changed value
                            type: string
                            pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                          value:
                            title: Value
                            description: The new value applied to the given address
                            type: string
                            pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              deprecated_declared_classes:
                title: Deprecated declared classes
                type: array
                items:
                  title: Field element
                  description: A field element. Represented by at most 63 hex digits
                  type: string
                  pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              declared_classes:
                title: Declared classes
                type: array
                items:
                  title: New classes
                  type: object
                  description: The declared class hash and compiled class hash
                  properties:
                    class_hash:
                      title: Class hash
                      description: The hash of the declared class
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    compiled_class_hash:
                      title: Compiled class hash
                      description: The Cairo assembly hash corresponding to the declared class
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              deployed_contracts:
                title: Deployed contracts
                type: array
                items:
                  title: Deployed contract item
                  type: object
                  required:
                    - address
                    - class_hash
                  properties:
                    address:
                      title: Address
                      description: The address of the contract
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    class_hash:
                      title: Class hash
                      description: The hash of the contract code
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              replaced_classes:
                title: Replaced classes
                type: array
                items:
                  title: Replaced class
                  type: object
                  description: The list of contracts whose class was replaced
                  properties:
                    contract_address:
                      title: Contract address
                      description: The address of the contract whose class was replaced
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    class_hash:
                      title: Class hash
                      description: The new class hash
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              nonces:
                title: Nonces
                type: array
                items:
                  title: Nonce update
                  type: object
                  description: The updated nonce per contract address
                  properties:
                    contract_address:
                      title: Contract address
                      description: The address of the contract
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    nonce:
                      title: Nonce
                      description: The nonce for the given address at the end of the block
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
```
