> For the complete documentation index, see [llms.txt](https://docs.bsvblockchain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bsvblockchain.org/network-topology/spv-wallet/developer-docs/block-headers-service.md).

# Block Headers Service

The Block Headers Service is a standalone service that communicates with the Bitcoin network using the P2P protocol. It is used to retrieve block headers and data related to them.

## Table of Contents

* [How it is used in the SPV Wallet ecosystem](#how-it-is-used-in-the-spv-wallet-ecosystem)
* [How merkle roots are verified](#how-merkle-roots-are-verified)
* [Authentication](/network-topology/spv-wallet/developer-docs/block-headers-service/authentication.md)
* [Configuration](/network-topology/spv-wallet/developer-docs/block-headers-service/configuration.md)

## How it is used in the SPV Wallet ecosystem

The Block Headers Service (BHS) is used by the SPV Wallet to verify the validity of merkle roots.

This service exposes a REST API with multiple endpoints, the most important from the SPV Wallet user perspective is:

`GET /chain/merkleroots/verify`

![Merkle Roots Verify](https://2147185133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWtK4ab0ntyPZBmGoKq4t%2Fuploads%2Fgit-blob-7a9f52cecdba329e6976c84251ed6f5afcd62aa0%2Fmerkleroots.jpg?alt=media)

## How merkle roots are verified

The SPV Wallet sends a request to the BHS with an array of merkle roots and the block height.

```json
[
  {
    "blockHeight": 0,
    "merkleRoot": "string"
  }
]
```

The BHS should return an object which contains general information about confirmation process called `confirmationState` and an array of validated merkle roots with blockHash, blockHeight, confirmation state and merkleRoot.

```json
[
  {
    "confirmationState": "CONFIRMED",
    "confirmations": [
      {
        "blockHash": "string",
        "blockHeight": 0,
        "confirmation": "CONFIRMED",
        "merkleRoot": "string"
      }
    ]
  }
]
```

Confirmation passes only if both - blockHeight and merkleRoot are valid pair.

> :warning: **Note**: BHS only checks for merkle roots in Longest Chain. It does not check for merkle roots in Side Chains.
>
> :warning: **Note**: There might be a case that merkle root is valid but BHS does not have it in its database. It happens when the block is freshly mined and BHS did not receive it yet.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.bsvblockchain.org/network-topology/spv-wallet/developer-docs/block-headers-service.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
