# Using the hBK Demo App

{% hint style="info" %}

## 📜 **TL;DR:**

* The [Hemi Bitcoin Kit (hBK) Demo App](https://bitcoin-kit.hemi.xyz/code-editor) enables seamless interaction with Bitcoin data in an Ethereum-compatible environment.
* Key features include:
  * Query [Bitcoin address balances](#id-1.-get-address-balance).
  * Retrieve the [latest block header](#id-2.-get-latest-block-header) or specific [block headers by height](#id-3.-get-block-header-by-height).
  * Fetch [Bitcoin transaction details](#id-4.-get-transaction-details) and [confirmation counts.](#id-5.-get-transaction-confirmations)
  * [List UTXOs](#id-6.-list-address-utxos) (Unspent Transaction Outputs) for a Bitcoin address.
* Developers can easily integrate Bitcoin data into dApps without external services, simplifying Bitcoin-aware application development.
  {% endhint %}

***

## 🌐 Overview

* The [Hemi Bitcoin Kit (hBK) Demo App](https://bitcoin-kit.hemi.xyz/code-editor) is a tool designed for developers to interact with Bitcoin blockchain data directly from an Ethereum-compatible environment.&#x20;
* This demo app provides a user-friendly interface for querying Bitcoin information.
* By abstracting the complexities of interacting with Bitcoin data, the app allows developers to seamlessly retrieve and use Bitcoin blockchain data in their dApps without needing external services.&#x20;
* This makes it an effective resource for experimenting with Bitcoin-aware applications and understanding hBK’s capabilities within the Hemi ecosystem.

***

## 🏁 Prerequisites

To follow along, you’ll need:

* Nothing!

***

## 1. Get Address Balance

Retrieves the current balance (in satoshis) of a specified Bitcoin address.

<figure><img src="https://3063395300-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBrGAUP9hcnvqWQvHZlN0%2Fuploads%2FXyzCARdaJY7DOmgEFC7a%2Fimage.png?alt=media&#x26;token=b3afed93-91bd-41e4-92d3-45d13d621501" alt=""><figcaption></figcaption></figure>

```
// Sample output
514853116
```

**Verifying our Output**

Navigate to <https://blockstream.info> and input the Bitcoin address to confirm the above output.

<figure><img src="https://3063395300-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBrGAUP9hcnvqWQvHZlN0%2Fuploads%2F7IcUD3SSsxxobmuJoqD5%2Fimage.png?alt=media&#x26;token=f5252946-7e5e-4034-99f5-41624086d436" alt=""><figcaption></figcaption></figure>

***

## 2. Get Latest Block Header

Returns the latest Bitcoin block header containing metadata like hash, height, and timestamp.

<figure><img src="https://3063395300-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBrGAUP9hcnvqWQvHZlN0%2Fuploads%2F42qVZ8yJgJOCBdLiDEVj%2Fimage.png?alt=media&#x26;token=81fef230-84d9-432b-a116-8570103c4166" alt=""><figcaption></figcaption></figure>

```
// Sample output
{
  "height": 3520643,
  "blockHash": "0x00000000002be0cd198317218f374a484bd0b3c5fe4eaf098bb5dfc97d0fb8a7",
  "version": 536870912,
  "previousBlockHash": "0x00000000000000019bebcf5e1d1dc6baf664c5859f82add17f5543b3018c82de",
  "merkleRoot": "0xcc50e3a3ca39e37a7ccd5867a7f2a82192c98861f28a50d94f558305672d65de",
  "timestamp": 1733342457,
  "bits": 486604799,
  "nonce": 1100503385
}
```

**Verifying our Output**

Navigate to <https://blockstream.info> and input the Block header to confirm the above output.

<figure><img src="https://3063395300-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBrGAUP9hcnvqWQvHZlN0%2Fuploads%2FBgFfuqSiv67J1IO2VFke%2Fimage.png?alt=media&#x26;token=f6592594-06c0-405a-8ef2-07d97db5ca9c" alt=""><figcaption></figcaption></figure>

***

## 3. Get Block Header by Height

Fetches the block header for a specific block height.

<figure><img src="https://3063395300-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBrGAUP9hcnvqWQvHZlN0%2Fuploads%2FqSPSLHfmTFVwxlcvzjIL%2Fimage.png?alt=media&#x26;token=9c97e3e2-1371-4971-b051-2740531414d1" alt=""><figcaption></figcaption></figure>

```
// Sample output
{
  "height": 1321358,
  "blockHash": "0x000000000000023bf34cd847acfcd73ad3b010f9a9434069e9bc5941cf61a1bf",
  "version": 536870912,
  "previousBlockHash": "0x00000000000002d213e95ae971060d49f93d51c3ce0ac84c452f76a45c962036",
  "merkleRoot": "0xd0f34249cd9b3929b56a418ab6fe965e685f1765f2dcd605ed08a1382199e506",
  "timestamp": 1527980035,
  "bits": 436539705,
  "nonce": 3252632758
}
```

**Verifying our Output**

Navigate to <https://blockstream.info> and input the Block header height to confirm the above output.

<figure><img src="https://3063395300-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBrGAUP9hcnvqWQvHZlN0%2Fuploads%2FgsxAm7mVVfWgvQBfQ9vy%2Fimage.png?alt=media&#x26;token=b556abfa-beb6-41b8-afcb-7fc658a775a7" alt=""><figcaption></figcaption></figure>

***

## 4. Get Transaction Details

Fetches the details of a Bitcoin transaction using its transaction ID, including all of its inputs and outputs.

<figure><img src="https://3063395300-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBrGAUP9hcnvqWQvHZlN0%2Fuploads%2F2noCflfs6YgxpZnjetZQ%2Fimage.png?alt=media&#x26;token=60fed774-625a-4251-ba2c-bbd08141c0ae" alt=""><figcaption></figcaption></figure>

```
// Sample output

{
  "containingBlockHash": "0x00000000280425e8f1f2170230b3946bf4bf058d5ef9677a3f361d2fbead994f",
  "transactionVersion": "2",
  "size": "116",
  "vSize": "116",
  "lockTime": "0",
  "inputs": [
    {
      "inValue": "4834",
      "inputTxId": "0xe7b262c5ead12343f1c5734b65848fbe19362907fafcd9d07c999c9aa2ec79f0",
      "sourceIndex": "11689",
      "scriptSig": "0x",
      "sequence": "2",
      "fullScriptSigLength": "0",
      "containsFullScriptSig": false
    }
  ],
  "outputs": [],
  "totalInputs": "1",
  "totalOutputs": "0",
  "containsAllInputs": true,
  "containsAllOutputs": true
}
```

**Verifying our Output**

Navigate to <https://blockstream.info> and input the transaction ID to confirm the above output.

***

## 5. Get Transaction Confirmations

Retrieves the number of confirmations for a specific transaction based on its transaction ID.

<figure><img src="https://3063395300-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBrGAUP9hcnvqWQvHZlN0%2Fuploads%2F8caf53xxPmwktp4eDAEc%2Fimage.png?alt=media&#x26;token=089214e5-0e10-4044-b33c-8cab06531db6" alt=""><figcaption></figcaption></figure>

```
// Sample output
653358
```

**Verifying our Output**

Navigate to <https://blockstream.info> and input the transaction ID to confirm the above output.

***

## 6. List Address UTXOs

Returns the UTXOs (Unspent Transaction Outputs) of a Bitcoin address, with pagination support.

<figure><img src="https://3063395300-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBrGAUP9hcnvqWQvHZlN0%2Fuploads%2Fw6ElVvWnRoSquEaD4NDj%2Fimage.png?alt=media&#x26;token=8944c199-4a5a-4903-9025-49c7fb4c3ab9" alt=""><figcaption></figcaption></figure>

```
// Sample output
[
  {
    "txId": "0xbd7b64df58115ca4e9c273b0bae477de3607154412a517dc31fdf5cd9f46e048",
    "index": "0",
    "value": "197506250"
  },
  {
    "txId": "0x452142a3dc4c9231ef8fd26674fa31ad55dfac5e880183d4b9d7452dd84e8b4f",
    "index": "0",
    "value": "199244750"
  },
  ...
]
```

**Verifying our Output**

Navigate to <https://blockstream.info> and input the Bitcoin address to confirm the above output.
