# starknet_call

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

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

Calls a function in a contract and returns the return value. Using this call will not create a transaction; hence, will not change the state


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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| request | object | Yes | The details of the function call |
| block_id | object or enum | Yes | The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on.  |

## Result

**result** (string[]): The function's return value

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

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'starknet_call',
    params: [
      {
        contract_address: 'string',
        entry_point_selector: 'string',
        calldata: ['string']
      },
      {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_call",
    "params": [{
            "contract_address": "string",
            "entry_point_selector": "string",
            "calldata": ["string"]
        }, { "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_call\",\n  \"params\": [\n    {\n      \"contract_address\": \"string\",\n      \"entry_point_selector\": \"string\",\n      \"calldata\": [\n        \"string\"\n      ]\n    },\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_call\",\n  \"params\": [\n    {\n      \"contract_address\": \"string\",\n      \"entry_point_selector\": \"string\",\n      \"calldata\": [\n        \"string\"\n      ]\n    },\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_call\",\n  \"params\": [\n    {\n      \"contract_address\": \"string\",\n      \"entry_point_selector\": \"string\",\n      \"calldata\": [\n        \"string\"\n      ]\n    },\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_call
summary: Call a StarkNet function without creating a StarkNet transaction
description: |
  Calls a function in a contract and returns the return value. Using this call will not create a transaction; hence, will not change the state
params:
  - name: request
    description: The details of the function call
    required: true
    schema:
      title: Function call
      type: object
      description: Function call information
      required:
        - contract_address
        - entry_point_selector
        - calldata
      properties:
        contract_address:
          title: Contract address
          description: A contract address
          type: string
          pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
        entry_point_selector:
          title: Entry point selector
          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})$
        calldata:
          title: Calldata
          type: array
          description: The parameters passed to the function
          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})$
  - name: block_id
    description: |
      The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on.
    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 function's return value
  schema:
    type: array
    title: Field element
    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})$
```
