# getblockheader

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

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

Returns the block header for the specified block hash.


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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| blockhash | string | Yes | The block hash to retrieve the header for. |
| verbose | boolean | No | Whether to return a JSON object (true) or raw hex-encoded string (false). Default is true.  |

## Result

**result** (object or string): The block header as an object or hex string depending on verbose.

## Example

### Request

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

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "hash": "00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80",
    "confirmations": 154,
    "height": 894470,
    "version": 537067520,
    "versionHex": "20030000",
    "merkleroot": "9d93ae25de98e5ed33aec9ccfea612c3b5b181a60171ba564ec1634786b04bc6",
    "time": 1745931642,
    "mediantime": 1745928076,
    "nonce": 766301978,
    "bits": "170248b6",
    "difficulty": 123234387977050.9,
    "chainwork": "0000000000000000000000000000000000000000bf64054821a76841a63cb26e",
    "nTx": 2186,
    "previousblockhash": "00000000000000000001aa9a63c6c0774a767f7a4d37d2bce3658728de76a146",
    "nextblockhash": "00000000000000000000cb8a1d7945b960985579525957bcc37b22174f1ecb31"
  },
  "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": "getblockheader",
  "params": [
    "00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80",
    true
  ]
}'
```

### JavaScript

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

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": "getblockheader",
    "params": ["00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80", True]
}
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\": \"getblockheader\",\n  \"params\": [\n    \"00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80\",\n    true\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\": \"getblockheader\",\n  \"params\": [\n    \"00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80\",\n    true\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\": \"getblockheader\",\n  \"params\": [\n    \"00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80\",\n    true\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getblockheader
summary: Get block header by block hash
description: |
  Returns the block header for the specified block hash.
params:
  - name: blockhash
    required: true
    description: The block hash to retrieve the header for.
    schema:
      title: Bitcoin Block Hash
      type: string
      pattern: ^[a-fA-F0-9]{64}$
      description: A 64-character hex string representing the block hash.
  - name: verbose
    required: false
    description: |
      Whether to return a JSON object (true) or raw hex-encoded string (false). Default is true.
    schema:
      type: boolean
      default: true
result:
  name: result
  description: The block header as an object or hex string depending on verbose.
  schema:
    oneOf:
      - title: Block Header (Verbose = true)
        type: object
        required:
          - hash
          - confirmations
          - height
          - version
          - versionHex
          - merkleroot
          - time
          - mediantime
          - nonce
          - bits
          - difficulty
          - chainwork
          - nTx
          - previousblockhash
          - nextblockhash
        properties:
          hash:
            type: string
            description: Hash of the block.
          confirmations:
            type: integer
            description: Number of confirmations, or -1 if not on main chain.
          height:
            type: integer
            description: Block height or index.
          version:
            type: integer
            description: Block version.
          versionHex:
            type: string
            description: Block version in hex.
          merkleroot:
            type: string
            description: Merkle root of the block.
          time:
            type: integer
            description: Block time (UNIX timestamp).
          mediantime:
            type: integer
            description: Median time of previous 11 blocks.
          nonce:
            type: integer
            description: Nonce used to generate this block.
          bits:
            type: string
            description: Compact target (difficulty) representation.
          difficulty:
            type: number
            format: double
            description: Network difficulty at time of block.
          chainwork:
            type: string
            description: Expected number of hashes to produce the chain up to this block.
          nTx:
            type: integer
            description: Number of transactions in the block.
          previousblockhash:
            type: string
            description: Hash of the previous block.
          nextblockhash:
            type: string
            description: Hash of the next block.
      - type: string
        description: Hex-encoded block header
examples:
  - name: getblockheader example
    params:
      - name: blockhash
        value: 00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80
      - name: verbose
        value: true
    result:
      name: result
      value:
        hash: 00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80
        confirmations: 154
        height: 894470
        version: 537067520
        versionHex: '20030000'
        merkleroot: 9d93ae25de98e5ed33aec9ccfea612c3b5b181a60171ba564ec1634786b04bc6
        time: 1745931642
        mediantime: 1745928076
        nonce: 766301978
        bits: 170248b6
        difficulty: 123234387977050.9
        chainwork: 0000000000000000000000000000000000000000bf64054821a76841a63cb26e
        nTx: 2186
        previousblockhash: 00000000000000000001aa9a63c6c0774a767f7a4d37d2bce3658728de76a146
        nextblockhash: 00000000000000000000cb8a1d7945b960985579525957bcc37b22174f1ecb31
```
