# starknet_getEvents

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

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

Returns all event objects matching the conditions in the provided filter

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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| filter | object | Yes | The conditions used to filter the returned events |

## Result

**events** (object): All the event objects matching the filter

## 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_getEvents",
  "params": [
    {
      "from_block": {
        "block_hash": "string"
      },
      "to_block": {
        "block_hash": "string"
      },
      "address": "string",
      "keys": [
        [
          "string"
        ]
      ],
      "continuation_token": "string",
      "chunk_size": 1
    }
  ]
}'
```

### JavaScript

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

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_getEvents",
    "params": [
        {
            "from_block": { "block_hash": "string" },
            "to_block": { "block_hash": "string" },
            "address": "string",
            "keys": [["string"]],
            "continuation_token": "string",
            "chunk_size": 1
        }
    ]
}
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_getEvents\",\n  \"params\": [\n    {\n      \"from_block\": {\n        \"block_hash\": \"string\"\n      },\n      \"to_block\": {\n        \"block_hash\": \"string\"\n      },\n      \"address\": \"string\",\n      \"keys\": [\n        [\n          \"string\"\n        ]\n      ],\n      \"continuation_token\": \"string\",\n      \"chunk_size\": 1\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_getEvents\",\n  \"params\": [\n    {\n      \"from_block\": {\n        \"block_hash\": \"string\"\n      },\n      \"to_block\": {\n        \"block_hash\": \"string\"\n      },\n      \"address\": \"string\",\n      \"keys\": [\n        [\n          \"string\"\n        ]\n      ],\n      \"continuation_token\": \"string\",\n      \"chunk_size\": 1\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_getEvents\",\n  \"params\": [\n    {\n      \"from_block\": {\n        \"block_hash\": \"string\"\n      },\n      \"to_block\": {\n        \"block_hash\": \"string\"\n      },\n      \"address\": \"string\",\n      \"keys\": [\n        [\n          \"string\"\n        ]\n      ],\n      \"continuation_token\": \"string\",\n      \"chunk_size\": 1\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: starknet_getEvents
summary: Returns all events matching the given filter
description: Returns all event objects matching the conditions in the provided filter
params:
  - name: filter
    description: The conditions used to filter the returned events
    required: true
    schema:
      title: Events request
      description: An event filter/query
      type: object
      required:
        - chunk_size
      properties:
        from_block:
          title: From block
          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
        to_block:
          title: To block
          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
        address:
          title: From contract
          description: A contract address
          type: string
          pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
        keys:
          title: Keys
          description: The values used to filter the events
          type: array
          items:
            title: Keys
            description: |
              Per key (by position), designate the possible values to be matched for events to be returned. An empty array designates 'any' value.
            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})$
        continuation_token:
          title: Continuation token
          description: |
            The token returned from the previous query. If no token is provided, the first page is returned.
          type: string
        chunk_size:
          title: Chunk size
          type: integer
          minimum: 1
result:
  name: events
  description: All the event objects matching the filter
  schema:
    title: Events chunk
    type: object
    required:
      - events
    properties:
      events:
        title: Matching Events
        type: array
        items:
          title: Emitted event
          description: |
            Event information decorated with metadata on where it was emitted. An event emitted as a result of transaction execution.
          type: object
          required:
            - data
            - from_address
            - keys
            - transaction_hash
          properties:
            from_address:
              title: From address
              description: A contract address
              type: string
              pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
            keys:
              title: Keys
              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})$
            data:
              title: Data
              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})$
            block_hash:
              title: Block hash
              description: The hash of the block in which the event was emitted
              type: string
              pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
            block_number:
              title: Block number
              description: The number of the block in which the event was emitted
              type: integer
              minimum: 0
            transaction_hash:
              title: Transaction hash
              description: The transaction that emitted the event
              type: string
              pattern: ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$
      continuation_token:
        title: Continuation token
        description: |
          Use this token in a subsequent query to obtain the next page. Should not appear if there are no more pages.
        type: string
```
