# getchaintxstats

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

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

Calculates statistics about the overall transaction rate and volume of the blockchain over a window of blocks.


Reference: https://www.alchemy.com/docs/chains/bitcoin/bitcoin-api-endpoints/getchaintxstats

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| nblocks | integer | No | The size of the window in number of blocks. Defaults to approximately one month. |
| blockhash | string | No | The block hash at which the window ends. Defaults to chain tip. |

## Result

**result** (object): The calculated chain transaction statistics.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getchaintxstats",
  "params": [
    0,
    "00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80"
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "time": 1745931642,
    "txcount": 1184990717,
    "window_final_block_hash": "00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80",
    "window_final_block_height": 894470,
    "window_block_count": 0
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getchaintxstats",
  "params": [
    1,
    "00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getchaintxstats',
    params: [1, '00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80']
  })
};

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

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getchaintxstats",
    "params": [1, "00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80"]
}
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://bitcoin-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getchaintxstats\",\n  \"params\": [\n    1,\n    \"00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80\"\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://bitcoin-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getchaintxstats\",\n  \"params\": [\n    1,\n    \"00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80\"\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://bitcoin-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\": \"getchaintxstats\",\n  \"params\": [\n    1,\n    \"00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80\"\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getchaintxstats
summary: Get chain transaction statistics
description: |
  Calculates statistics about the overall transaction rate and volume of the blockchain over a window of blocks.
params:
  - name: nblocks
    required: false
    description: The size of the window in number of blocks. Defaults to approximately one month.
    schema:
      type: integer
  - name: blockhash
    required: false
    description: The block hash at which the window ends. Defaults to chain tip.
    schema:
      type: string
      pattern: ^[a-fA-F0-9]{64}$
result:
  name: result
  description: The calculated chain transaction statistics.
  schema:
    title: Bitcoin Chain Transaction Statistics
    type: object
    required:
      - time
      - txcount
      - window_final_block_hash
      - window_final_block_height
      - window_block_count
    properties:
      time:
        type: integer
        description: Timestamp for the last block in the window (UNIX epoch).
      txcount:
        type: integer
        description: Total number of transactions up to the final block.
      window_final_block_hash:
        type: string
        description: Hash of the final block in the window.
      window_final_block_height:
        type: integer
        description: Height of the final block in the window.
      window_block_count:
        type: integer
        description: Number of blocks included in the window.
      window_tx_count:
        type: integer
        description: Number of transactions in the window.
      window_interval:
        type: integer
        description: Elapsed time (in seconds) across the window.
      txrate:
        type: number
        format: double
        description: Average transaction rate per second across the window.
examples:
  - name: getchaintxstats example
    params:
      - name: nblocks
        value: 0
      - name: blockhash
        value: 00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80
    result:
      name: result
      value:
        time: 1745931642
        txcount: 1184990717
        window_final_block_hash: 00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80
        window_final_block_height: 894470
        window_block_count: 0
```
