# starknet_getClass

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

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

Get the contract class definition in the given block associated with the given hash

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

## 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  |
| class_hash | string | Yes | The hash of the requested contract class |

## Result

**result** (object): The contract class, if found

## 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_getClass",
  "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_getClass',
    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_getClass",
    "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_getClass\",\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_getClass\",\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_getClass\",\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_getClass
description: Get the contract class definition in the given block associated with the given hash
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: class_hash
    description: The hash of the requested contract class
    required: true
    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})$
result:
  name: result
  description: The contract class, if found
  schema:
    title: Starknet get class result
    oneOf:
      - title: Deprecated contract class
        description: The definition of a StarkNet contract class
        type: object
        required:
          - program
          - entry_points_by_type
        properties:
          program:
            title: Program
            type: string
            description: A base64 representation of the compressed program code
            pattern: ^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$
          entry_points_by_type:
            title: Deprecated entry points by type
            type: object
            properties:
              CONSTRUCTOR:
                title: Deprecated constructor
                type: array
                items:
                  title: Deprecated Cairo entry point
                  type: object
                  required:
                    - offset
                    - selector
                  properties:
                    offset:
                      title: Offset
                      description: The offset of the entry point in the program
                      type: string
                      pattern: ^0x[a-fA-F0-9]+$
                    selector:
                      title: Selector
                      description: A unique identifier of the entry point (function) in the program
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              EXTERNAL:
                title: Deprecated external
                type: array
                items:
                  title: Deprecated Cairo entry point
                  type: object
                  required:
                    - offset
                    - selector
                  properties:
                    offset:
                      title: Offset
                      description: The offset of the entry point in the program
                      type: string
                      pattern: ^0x[a-fA-F0-9]+$
                    selector:
                      title: Selector
                      description: A unique identifier of the entry point (function) in the program
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
              L1_HANDLER:
                title: Deprecated L1 handler
                type: array
                items:
                  title: Deprecated Cairo entry point
                  type: object
                  required:
                    - offset
                    - selector
                  properties:
                    offset:
                      title: Offset
                      description: The offset of the entry point in the program
                      type: string
                      pattern: ^0x[a-fA-F0-9]+$
                    selector:
                      title: Selector
                      description: A unique identifier of the entry point (function) in the program
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
          abi:
            title: Contract ABI
            type: array
            items:
              title: Contract ABI entry
              oneOf:
                - title: Function ABI entry
                  type: object
                  required:
                    - type
                    - name
                    - inputs
                    - outputs
                  properties:
                    type:
                      title: Function ABI type
                      type: string
                      enum:
                        - function
                        - l1_handler
                        - constructor
                    name:
                      title: Function name
                      description: The function name
                      type: string
                    inputs:
                      title: Inputs
                      type: array
                      items:
                        title: Typed parameter
                        type: object
                        required:
                          - name
                          - type
                        properties:
                          name:
                            title: Parameter name
                            description: The parameter's name
                            type: string
                          type:
                            title: Parameter type
                            description: The parameter's type
                            type: string
                    outputs:
                      title: Outputs
                      type: array
                      items:
                        title: Typed parameter
                        type: object
                        required:
                          - name
                          - type
                        properties:
                          name:
                            title: Parameter name
                            description: The parameter's name
                            type: string
                          type:
                            title: Parameter type
                            description: The parameter's type
                            type: string
                    stateMutability:
                      title: Function state mutability
                      type: string
                      enum:
                        - view
                - title: Event ABI entry
                  type: object
                  required:
                    - type
                    - name
                    - keys
                    - data
                  properties:
                    type:
                      title: Event ABI type
                      type: string
                      enum:
                        - event
                    name:
                      title: Event name
                      description: The event name
                      type: string
                    keys:
                      title: Keys
                      type: array
                      items:
                        title: Typed parameter
                        type: object
                        required:
                          - name
                          - type
                        properties:
                          name:
                            title: Parameter name
                            description: The parameter's name
                            type: string
                          type:
                            title: Parameter type
                            description: The parameter's type
                            type: string
                    data:
                      title: Data
                      type: array
                      items:
                        title: Typed parameter
                        type: object
                        required:
                          - name
                          - type
                        properties:
                          name:
                            title: Parameter name
                            description: The parameter's name
                            type: string
                          type:
                            title: Parameter type
                            description: The parameter's type
                            type: string
                - title: Struct ABI entry
                  type: object
                  required:
                    - type
                    - name
                    - size
                    - members
                  properties:
                    type:
                      title: Struct ABI type
                      type: string
                      enum:
                        - struct
                    name:
                      title: Struct name
                      description: The struct name
                      type: string
                    size:
                      title: Size
                      type: integer
                      minimum: 1
                    members:
                      title: Members
                      type: array
                      items:
                        title: Struct member
                        type: object
                        required:
                          - name
                          - type
                        properties:
                          name:
                            title: Parameter name
                            description: The parameter's name
                            type: string
                          type:
                            title: Parameter type
                            description: The parameter's type
                            type: string
                          offset:
                            title: Offset
                            description: Offset of this property within the struct
                            type: integer
      - title: Contract class
        type: object
        required:
          - sierra_program
          - contract_class_version
          - entry_points_by_type
        properties:
          sierra_program:
            title: Sierra program
            type: array
            description: The list of Sierra instructions of which the program consists
            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})$
          contract_class_version:
            title: Contract class version
            type: string
            description: The version of the contract class object. Currently, the Starknet OS supports version 0.1.0
          entry_points_by_type:
            title: Entry points by type
            type: object
            required:
              - CONSTRUCTOR
              - EXTERNAL
              - L1_HANDLER
            properties:
              CONSTRUCTOR:
                title: Constructor
                type: array
                items:
                  title: Sierra entry point
                  type: object
                  required:
                    - selector
                    - function_idx
                  properties:
                    selector:
                      title: Selector
                      description: A unique identifier of the entry point (function) in the program
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    function_idx:
                      title: Function index
                      description: The index of the function in the program
                      type: integer
              EXTERNAL:
                title: External
                type: array
                items:
                  title: Sierra entry point
                  type: object
                  required:
                    - selector
                    - function_idx
                  properties:
                    selector:
                      title: Selector
                      description: A unique identifier of the entry point (function) in the program
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    function_idx:
                      title: Function index
                      description: The index of the function in the program
                      type: integer
              L1_HANDLER:
                title: L1 handler
                type: array
                items:
                  title: Sierra entry point
                  type: object
                  required:
                    - selector
                    - function_idx
                  properties:
                    selector:
                      title: Selector
                      description: A unique identifier of the entry point (function) in the program
                      type: string
                      pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
                    function_idx:
                      title: Function index
                      description: The index of the function in the program
                      type: integer
          abi:
            title: ABI
            type: string
            description: The class ABI, as supplied by the user declaring the class
```
