# trace_filter

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

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

Returns traces matching a given filter.

Reference: https://www.alchemy.com/docs/node/trace-api/trace-api-endpoints/trace-filter

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| filter | object | Yes | Filter object for retrieving traces.  |

## Result

**Filtered Traces** (object[]): Returns an array of traces that match the filter.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "trace_filter",
  "params": [
    {
      "fromBlock": "0xc26f54",
      "toBlock": "0xc26f54",
      "fromAddress": [
        "0x15dce17509846b420b1f5c158fe3d7518204abb6"
      ],
      "toAddress": [
        "0x15dce17509846b420b1f5c158fe3d7518204abb6"
      ],
      "after": "0x0",
      "count": 10
    }
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "jsonrpc": "2.0",
    "id": 0,
    "result": [
      {
        "name": "trace item",
        "value": {
          "action": {
            "callType": "call",
            "from": "0x15dce17509846b420b1f5c158fe3d7518204abb6",
            "gas": "0xed2a4",
            "input": "0x00000000000000000000000000abc3136b63363200000000000000000000000000708a100000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001f0000000016128acb08000000cb0c5d9d92f4f2f80cce7aa271a1e148c226e19d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000008ae720a71622e824f576b4a8c03031066548a3b1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000075cf0c1848f9db946ab000000000000000000000000fffd8963efd1fc6a506488495d951d5263988d2500000000000000000000000000000000000000000000000000000000000000"
          },
          "blockHash": "0xe0583a364c20fa67748ca92e276df63919c67e12fdc9bdbc17deae8cf730cf35",
          "blockNumber": "12742484",
          "result": {
            "gasUsed": "0x4551d",
            "output": "0x00000000000000000000000000000000000000000000000000d96b96f61c5e87",
            "subtraces": 12,
            "traceAddress": [],
            "transactionHash": "0x87951d0547018db2c4817282a53e2015d91934b42d1b8d8bba1bef7cb480f263",
            "transactionPosition": "0",
            "type": "call"
          }
        }
      },
      {
        "name": "trace item",
        "value": {
          "action": {
            "callType": "call",
            "from": "0x000000000000abe945c436595ce765a8a261317b",
            "gas": "0xe87a4",
            "input": "0x70a08231000000000000000000000000000000000000abe945c436595ce765a8a261317b",
            "to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
            "value": "0x0"
          },
          "blockHash": "0xe0583a364c20fa67748ca92e276df63919c67e12fdc9bdbc17deae8cf730cf35",
          "blockNumber": "12742484",
          "result": {
            "gasUsed": "0x4551d",
            "output": "0x00000000000000000000000000000000000000000000000000d96b96f61c5e87",
            "subtraces": 12,
            "traceAddress": [],
            "transactionHash": "0x87951d0547018db2c4817282a53e2015d91934b42d1b8d8bba1bef7cb480f263",
            "transactionPosition": "0",
            "type": "call"
          }
        }
      }
    ]
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://eth-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "trace_filter",
  "params": [
    {
      "fromBlock": "0xc26f54",
      "toBlock": "0xc26f54",
      "fromAddress": [
        "0x15dce17509846b420b1f5c158fe3d7518204abb6"
      ],
      "toAddress": [
        "0x15dce17509846b420b1f5c158fe3d7518204abb6"
      ],
      "after": "0x0",
      "count": 10
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'trace_filter',
    params: [
      {
        fromBlock: '0xc26f54',
        toBlock: '0xc26f54',
        fromAddress: ['0x15dce17509846b420b1f5c158fe3d7518204abb6'],
        toAddress: ['0x15dce17509846b420b1f5c158fe3d7518204abb6'],
        after: '0x0',
        count: 10
      }
    ]
  })
};

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

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "trace_filter",
    "params": [
        {
            "fromBlock": "0xc26f54",
            "toBlock": "0xc26f54",
            "fromAddress": ["0x15dce17509846b420b1f5c158fe3d7518204abb6"],
            "toAddress": ["0x15dce17509846b420b1f5c158fe3d7518204abb6"],
            "after": "0x0",
            "count": 10
        }
    ]
}
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://eth-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"trace_filter\",\n  \"params\": [\n    {\n      \"fromBlock\": \"0xc26f54\",\n      \"toBlock\": \"0xc26f54\",\n      \"fromAddress\": [\n        \"0x15dce17509846b420b1f5c158fe3d7518204abb6\"\n      ],\n      \"toAddress\": [\n        \"0x15dce17509846b420b1f5c158fe3d7518204abb6\"\n      ],\n      \"after\": \"0x0\",\n      \"count\": 10\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://eth-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"trace_filter\",\n  \"params\": [\n    {\n      \"fromBlock\": \"0xc26f54\",\n      \"toBlock\": \"0xc26f54\",\n      \"fromAddress\": [\n        \"0x15dce17509846b420b1f5c158fe3d7518204abb6\"\n      ],\n      \"toAddress\": [\n        \"0x15dce17509846b420b1f5c158fe3d7518204abb6\"\n      ],\n      \"after\": \"0x0\",\n      \"count\": 10\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://eth-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\": \"trace_filter\",\n  \"params\": [\n    {\n      \"fromBlock\": \"0xc26f54\",\n      \"toBlock\": \"0xc26f54\",\n      \"fromAddress\": [\n        \"0x15dce17509846b420b1f5c158fe3d7518204abb6\"\n      ],\n      \"toAddress\": [\n        \"0x15dce17509846b420b1f5c158fe3d7518204abb6\"\n      ],\n      \"after\": \"0x0\",\n      \"count\": 10\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: trace_filter
description: Returns traces matching a given filter.
params:
  - name: filter
    required: true
    description: |
      Filter object for retrieving traces.
    schema:
      type: object
      properties:
        fromBlock:
          title: hex encoded unsigned integer (any case)
          type: string
          pattern: ^0[xX]([1-9A-Fa-f]+[0-9A-Fa-f]*|0)$
          description: From this block.
          default: '0xc26f54'
        toBlock:
          title: hex encoded unsigned integer (any case)
          type: string
          pattern: ^0[xX]([1-9A-Fa-f]+[0-9A-Fa-f]*|0)$
          description: To this block.
          default: '0xc26f54'
        fromAddress:
          type: array
          description: Sent from these addresses.
          items:
            title: hex encoded address
            type: string
            pattern: ^0x[0-9a-fA-F]{40}$
        toAddress:
          type: array
          description: Sent to these addresses.
          items:
            title: hex encoded address
            type: string
            pattern: ^0x[0-9a-fA-F]{40}$
        after:
          type: string
          description: The offset trace number.
        count:
          type: integer
          description: Integer number of traces to display in a batch.
result:
  name: Filtered Traces
  description: Returns an array of traces that match the filter.
  schema:
    type: array
    items:
      type: object
      properties:
        action:
          type: object
          properties:
            callType:
              type: string
            from:
              title: hex encoded address
              type: string
              pattern: ^0x[0-9a-fA-F]{40}$
            gas:
              type: string
            input:
              type: string
            to:
              title: hex encoded address
              type: string
              pattern: ^0x[0-9a-fA-F]{40}$
            value:
              type: string
        blockHash:
          title: 32 byte hex value (any case)
          type: string
          pattern: ^0[xX][0-9A-Fa-f]{64}$
        blockNumber:
          type: string
        result:
          type: object
          properties:
            gasUsed:
              type: string
            output:
              type: string
            subtraces:
              type: integer
            traceAddress:
              type: array
              items:
                type: string
            transactionHash:
              title: 32 byte hex value (any case)
              type: string
              pattern: ^0[xX][0-9A-Fa-f]{64}$
            transactionPosition:
              type: string
            type:
              type: string
examples:
  - name: trace_filter example
    params:
      - name: filter
        value:
          fromBlock: '0xc26f54'
          toBlock: '0xc26f54'
          fromAddress:
            - '0x15dce17509846b420b1f5c158fe3d7518204abb6'
          toAddress:
            - '0x15dce17509846b420b1f5c158fe3d7518204abb6'
          after: '0x0'
          count: 10
    result:
      name: trace_filter response
      value:
        jsonrpc: '2.0'
        id: 0
        result:
          - name: trace item
            value:
              action:
                callType: call
                from: '0x15dce17509846b420b1f5c158fe3d7518204abb6'
                gas: '0xed2a4'
                input: '0x00000000000000000000000000abc3136b63363200000000000000000000000000708a100000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001f0000000016128acb08000000cb0c5d9d92f4f2f80cce7aa271a1e148c226e19d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000008ae720a71622e824f576b4a8c03031066548a3b1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000075cf0c1848f9db946ab000000000000000000000000fffd8963efd1fc6a506488495d951d5263988d2500000000000000000000000000000000000000000000000000000000000000'
              blockHash: '0xe0583a364c20fa67748ca92e276df63919c67e12fdc9bdbc17deae8cf730cf35'
              blockNumber: '12742484'
              result:
                gasUsed: '0x4551d'
                output: '0x00000000000000000000000000000000000000000000000000d96b96f61c5e87'
                subtraces: 12
                traceAddress: []
                transactionHash: '0x87951d0547018db2c4817282a53e2015d91934b42d1b8d8bba1bef7cb480f263'
                transactionPosition: '0'
                type: call
          - name: trace item
            value:
              action:
                callType: call
                from: '0x000000000000abe945c436595ce765a8a261317b'
                gas: '0xe87a4'
                input: '0x70a08231000000000000000000000000000000000000abe945c436595ce765a8a261317b'
                to: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
                value: '0x0'
              blockHash: '0xe0583a364c20fa67748ca92e276df63919c67e12fdc9bdbc17deae8cf730cf35'
              blockNumber: '12742484'
              result:
                gasUsed: '0x4551d'
                output: '0x00000000000000000000000000000000000000000000000000d96b96f61c5e87'
                subtraces: 12
                traceAddress: []
                transactionHash: '0x87951d0547018db2c4817282a53e2015d91934b42d1b8d8bba1bef7cb480f263'
                transactionPosition: '0'
                type: call
```
