# eth_newFilter

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

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

Creates a filter object based on filter options to notify when state changes (logs).

Reference: https://www.alchemy.com/docs/chains/pharos/pharos-api-endpoints/eth-new-filter

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Filter | object | Yes | The filter options object to specify the filter criteria for logs. |

## Result

**Filter identifier** (string): A hexadecimal string representing the ID of the created filter.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "eth_newFilter",
  "params": [
    {
      "fromBlock": "0x137d3c2",
      "toBlock": "0x137d3c3",
      "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
      "topics": []
    }
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": "0x01",
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://pharos-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_newFilter",
  "params": [
    {
      "fromBlock": "0x137d3c2",
      "toBlock": "0x137d3c3",
      "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
      "topics": []
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'eth_newFilter',
    params: [
      {
        fromBlock: '0x137d3c2',
        toBlock: '0x137d3c3',
        address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
        topics: []
      }
    ]
  })
};

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

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "eth_newFilter",
    "params": [
        {
            "fromBlock": "0x137d3c2",
            "toBlock": "0x137d3c3",
            "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
            "topics": []
        }
    ]
}
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://pharos-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_newFilter\",\n  \"params\": [\n    {\n      \"fromBlock\": \"0x137d3c2\",\n      \"toBlock\": \"0x137d3c3\",\n      \"address\": \"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n      \"topics\": []\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://pharos-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_newFilter\",\n  \"params\": [\n    {\n      \"fromBlock\": \"0x137d3c2\",\n      \"toBlock\": \"0x137d3c3\",\n      \"address\": \"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n      \"topics\": []\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://pharos-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\": \"eth_newFilter\",\n  \"params\": [\n    {\n      \"fromBlock\": \"0x137d3c2\",\n      \"toBlock\": \"0x137d3c3\",\n      \"address\": \"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n      \"topics\": []\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: eth_newFilter
description: Creates a filter object based on filter options to notify when state changes (logs).
params:
  - name: Filter
    required: true
    description: The filter options object to specify the filter criteria for logs.
    schema:
      title: filter
      type: object
      additionalProperties: false
      properties:
        fromBlock:
          title: from block
          oneOf:
            - title: Block number
              type: string
              pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
            - title: Block tag
              type: string
              enum:
                - earliest
                - finalized
                - safe
                - latest
                - pending
              description: '`earliest`: The lowest numbered block the client has available; `finalized`: The most recent crypto-economically secure block, cannot be re-orged outside of manual intervention driven by community coordination; `safe`: The most recent block that is safe from re-orgs under honest majority and certain synchronicity assumptions; `latest`: The most recent block in the canonical chain observed by the client, this block may be re-orged out of the canonical chain even under healthy/normal conditions; `pending`: A sample next block built by the client on top of `latest` and containing the set of transactions usually taken from local mempool. Before the merge transition is finalized, any call querying for `finalized` or `safe` block MUST be responded to with `-39001: Unknown block` error'
          description: Block number or tag to start searching from. Defaults to `latest`.
        toBlock:
          title: to block
          oneOf:
            - title: Block number
              type: string
              pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
            - title: Block tag
              type: string
              enum:
                - earliest
                - finalized
                - safe
                - latest
                - pending
              description: '`earliest`: The lowest numbered block the client has available; `finalized`: The most recent crypto-economically secure block, cannot be re-orged outside of manual intervention driven by community coordination; `safe`: The most recent block that is safe from re-orgs under honest majority and certain synchronicity assumptions; `latest`: The most recent block in the canonical chain observed by the client, this block may be re-orged out of the canonical chain even under healthy/normal conditions; `pending`: A sample next block built by the client on top of `latest` and containing the set of transactions usually taken from local mempool. Before the merge transition is finalized, any call querying for `finalized` or `safe` block MUST be responded to with `-39001: Unknown block` error'
          description: Block number or tag to end searching at. Defaults to `latest`.
        address:
          title: Address(es)
          oneOf:
            - title: Any Address
              type: 'null'
            - title: Address
              type: string
              pattern: ^0x[0-9a-fA-F]{40}$
            - title: Addresses
              type: array
              items:
                title: hex encoded address
                type: string
                pattern: ^0x[0-9a-fA-F]{40}$
        topics:
          title: Topics
          oneOf:
            - title: Any Topic Match
              type: 'null'
            - title: Specified Filter Topics
              type: array
              items:
                title: Filter Topic List Entry
                oneOf:
                  - title: Single Topic Match
                    type: string
                    pattern: ^0x[0-9a-f]{64}$
                  - title: Multiple Topic Match
                    type: array
                    items:
                      title: 32 hex encoded bytes
                      type: string
                      pattern: ^0x[0-9a-f]{64}$
result:
  name: Filter identifier
  description: A hexadecimal string representing the ID of the created filter.
  schema:
    title: hex encoded unsigned integer
    type: string
    pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
examples:
  - name: eth_newFilter example
    params:
      - name: Filter
        value:
          fromBlock: '0x137d3c2'
          toBlock: '0x137d3c3'
          address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
          topics: []
    result:
      name: Filter identifier
      value: '0x01'
```
