# starknet_getClassHashAt

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

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

Get the contract class hash in the given block for the contract deployed at the given address

Reference: https://www.alchemy.com/docs/chains/starknet/starknet-api-endpoints/starknet-get-class-hash-at

## 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  |
| contract_address | string | Yes | The address of the contract whose class hash will be returned |

## Result

**result** (string): The class hash of the given contract

## 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_getClassHashAt",
  "params": [
    {
      "block_hash": "string"
    },
    "string"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'starknet_getClassHashAt',
    params: [{block_hash: 'string'}, '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_getClassHashAt",
    "params": [{ "block_hash": "string" }, "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_getClassHashAt\",\n  \"params\": [\n    {\n      \"block_hash\": \"string\"\n    },\n    \"string\"\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_getClassHashAt\",\n  \"params\": [\n    {\n      \"block_hash\": \"string\"\n    },\n    \"string\"\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_getClassHashAt\",\n  \"params\": [\n    {\n      \"block_hash\": \"string\"\n    },\n    \"string\"\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: starknet_getClassHashAt
description: Get the contract class hash in the given block for the contract deployed at the given address
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
  - name: contract_address
    description: The address of the contract whose class hash will be returned
    required: true
    schema:
      title: Address
      description: A contract address
      type: string
      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
result:
  name: result
  description: The class hash of the given contract
  schema:
    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})$
```
