> For the complete documentation index, see [llms.txt](https://docs.taal.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.taal.com/core-products/whatsonchain/websockets/woc-sockets-v2-beta.md).

# WoC Sockets V2 (Beta)

{% code title="Example using WebSocket API client" %}

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>WOC Socket V2 - blockheaders (JSON format)</title>
  <script type="text/javascript">
    window.addEventListener('load', function() {
      const wsUrl = "wss://socket-v2.whatsonchain.com/websocket/blockheaders?format=json";
      let ws;
      let pingInterval;

      function doConnect() {
        console.log("[SocketV2] Connecting ->", wsUrl);
        ws = new WebSocket(wsUrl);

        ws.onopen = function(e) {
          console.log("[SocketV2] OPEN:", wsUrl, e);

          pingInterval = setInterval(() => {
            if (ws && ws.readyState === WebSocket.OPEN) {
              console.log("[SocketV2] Sending ping to server");
              ws.send('ping'); // Send ping as text message
            }
          }, 25000);
        };

        ws.onerror = function(e) {
          console.warn("[SocketV2] ERROR event – possibly normal if server closes. URL:", wsUrl);
        };

        ws.onclose = function(e) {
          console.log("[SocketV2] CLOSE:", wsUrl, e);

          // Clear ping interval when connection closes
          if (pingInterval) {
            clearInterval(pingInterval);
            pingInterval = null;
          }
        };

        ws.onmessage = async function(e) {
          if (!e.data) {
            console.log("[SocketV2] PING or empty message ->", wsUrl);
            return;
          }

          const blob = e.data;
          if (blob && blob.size > 0) {
            try {
              const text = await blob.text();

              // Handle ping/pong messages
              if (text === 'ping') {
                console.log("[SocketV2] Received ping from server, sending pong");
                ws.send('pong');
                return;
              }

              if (text === 'pong') {
                console.log("[SocketV2] Received pong from server");
                return;
              }

              console.log("[SocketV2] MESSAGE (JSON):", text);
            } catch (err) {
              console.log("[SocketV2] MESSAGE (error reading blob):", err);
            }
          } else {
            // Handle direct string messages
            const text = e.data;

            // Handle ping/pong messages
            if (text === 'ping') {
              console.log("[SocketV2] Received ping from server, sending pong");
              ws.send('pong');
              return;
            }

            if (text === 'pong') {
              console.log("[SocketV2] Received pong from server");
              return;
            }

            console.log("[SocketV2] MESSAGE (direct string):", text);
          }
        };
      }

      doConnect();
    });
  </script>
</head>
<body>
  <h1>WOC Socket V2 - blockheaders (JSON format)</h1>
  <p>Open the browser console to see messages from the WebSocket.</p>
</body>
</html>
```

{% endcode %}

## New Block Header Event

Receive new block header events in real time.

#### Mainnet URLs

{% tabs %}
{% tab title="BSV" %}

<pre><code><strong>wss://socket-v2.whatsonchain.com/websocket/blockheaders
</strong></code></pre>

{% endtab %}
{% endtabs %}

{% code title="Testnet URL (BSV)" %}

```
wss://socket-v2-testnet.whatsonchain.com/websocket/blockheaders
```

{% endcode %}

{% code title="Example Response" overflow="wrap" %}

```json
{
  "channel": "woc:blockHeader",
  "pub": {
    "data": {
      "hash": "000000000000000007405fd882e9d4bf3d7b2388010081fe443ee1e323d8a668",
      "confirmations": 1,
      "size": 368170789,
      "height": 892466,
      "version": 939524096,
      "versionHex": "38000000",
      "merkleroot": "b0ac43a40a42775d8f533a8eda00bed3257e12a5fca3c8cade47188e6b7aa382",
      "txcount": 9230,
      "time": 1744648860,
      "mediantime": 1744645401,
      "nonce": 2893086732,
      "bits": "181246e3",
      "difficulty": 60157618395.71893,
      "chainwork": "00000000000000000000000000000000000000000164d487adbc2b84d47d2831",
      "previousblockhash": "0000000000000000090fa4de4c971b0b3609acc1061b2020d22dc8d8bf72746a",
      "nextblockhash": "",
      "coinbaseTx": {
        "hex": "...",
        "txid": "1932aa0229b6b44be4b749b9e7279c02136374e2e77b4e890db761f8e74d2111",
        "hash": "1932aa0229b6b44be4b749b9e7279c02136374e2e77b4e890db761f8e74d2111",
        "size": 111,
        "version": 1,
        "locktime": 0,
        "vin": [
          {
            "n": 0,
            "coinbase": "03329e0d2f7461616c2e636f6d2fb9df41e723a18d95e09d0200",
            "sequence": 4294967295
          }
        ],
        "vout": [
          {
            "value": 3.13276008,
            "n": 0,
            "scriptPubKey": {
              "asm": "OP_DUP OP_HASH160 522cf9e7626d9bd8729e5a1398ece40dad1b6a2f OP_EQUALVERIFY OP_CHECKSIG",
              "hex": "...",
              "reqSigs": 1,
              "type": "pubkeyhash",
              "addresses": [
                "18VWHjMt4ixHddPPbs6righWTs3Sg2QNcn"
              ],
              "isTruncated": false
            },
            "scripthash": "1981f116576960fab6ac9a71ba3c12e4f98c2d9b34532bdb40f2e8cc03337fa2"
          }
        ],
        "blockhash": "000000000000000007405fd882e9d4bf3d7b2388010081fe443ee1e323d8a668",
        "confirmations": 1,
        "time": 1744648860,
        "blocktime": 1744648860,
        "blockheight": 892466,
        "vincount": 1,
        "voutcount": 1,
        "voutvalue": 3.13276008
      },
      "totalFees": 0.007760080000000169
    }
  }
}
```

{% endcode %}

## Block Headers History

Stream block headers between the provided block heights `from` and `to`.

#### Mainnet URLs

{% tabs %}
{% tab title="BSV" %}

```
wss://socket-v2.whatsonchain.com/websocket/blockheaders/history?from=<from>&to=<to>
```

{% endtab %}
{% endtabs %}

{% code title="Testnet URL (BSV)" %}

```
wss://socket-v2-testnet.whatsonchain.com/websocket/blockheaders/history?from=<from>&to=<to>
```

{% endcode %}

{% code title="Example Response" %}

```json
{
  "channel": "blockHeaders",
  "pub": {
    "data": {
      "version": 536870912,
      "previousblockhash": "4e4bc1c98159804f2c9c73fbf44100292a277a9747ba52f522490fd3502b3233",
      "merkleroot": "16c7262127cf64a42a406da9961c9223c2e35ebbb48c4e3e4af6f5ac99510772",
      "time": 1750787660,
      "bits": 545259519,
      "nonce": 5,
      "hash": "60111525d2acddf07f9eb9be1c8824d4462b0a696d3c32829d6864fde63067ff",
      "height": 7967
    }
  }
}
```

{% endcode %}

**URL Parameters**

| Parameter | Description                 |
| --------- | --------------------------- |
| from      | Block heigh to stream from. |
| to        | Block height to stream to.  |

## Block Transactions

Stream transactions from a block height and transaction index.

{% hint style="info" %}

* `hex`, `vin` and `vout` values are not published for message sizes greater than 10MB.&#x20;
* Recommended to fetch details for such transactions using the REST endpoints using the published txid value.
  {% endhint %}

#### Mainnet URLs

{% tabs %}
{% tab title="BSV" %}

```
wss://socket-v2.whatsonchain.com/websocket/block/transactions?from=<from>&to=<to>&txIndex=<txIndex>&format=<format>
```

{% endtab %}
{% endtabs %}

{% code title="Testnet URL (BSV)" %}

```
wss://socket-v2-testnet.whatsonchain.com/websocket/block/transactions?from=<from>&to=<to>&txIndex=<txIndex>&format=<format>
```

{% endcode %}

{% code title="Example Response" %}

```json
{
  "channel": "blockTxs",
  "pub": {
    "data": {
        "txid": "03dd6bc953033a2b5e283b64bc3852ebbcbc1a6120fb51088e9d40d94db41871",
        "hash": "03dd6bc953033a2b5e283b64bc3852ebbcbc1a6120fb51088e9d40d94db41871",
        "size": 263,
        "version": 1,
        "locktime": 0,
        "vin": [
            {
            "n": 0,
            "txid": "797bb9fe7ce40a1628d4e9a91637c555df7d429abcd51dfc774eb98c3efc7111",
            "vout": 2,
            "scriptSig": {
                "asm": "3045022100... 02e24a81ebae0...",
                "hex": "...",
                "isTruncated": false
            },
            "sequence": 4294967295
            }
        ],
        "vout": [
            {
            "value": 0,
            "n": 0,
            "scriptPubKey": {
                "asm": "0 OP_RETURN 746478702e617070 703a313337303439322c70726f666974",
                "hex": "006a08746478702e61707010703a...",
                "type": "nulldata",
                "isTruncated": false
            },
            "scripthash": "2ac0e4bef9f2..."
            },
            ...
        ],
        "vincount": 1,
        "voutcount": 3,
        "voutvalue": 2.2054052100000003
    }
  }
}
```

{% endcode %}

**URL Parameters**

| Parameter          | Description                                                                                                                  |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------- |
| from               | Block height to stream from.                                                                                                 |
| to                 | Block height to stream to.                                                                                                   |
| txIndex (optional) | Transaction index as a starting point in the first block to deliver. Default value `0`.                                      |
| format (optional)  | `hex` (default) or `json`. If `hex`, the response will include transaction *hex* and metadata. If `json`, `hex` is excluded. |

## Mempool Transactions

Receive mempool transactions in real time.

* Mempool transactions are collected from multiple nodes.
* Client side should be idempotent because duplicate transaction events are not guaranteed to have been removed.
* *hex*, *vin* and *vout* values are not published for message sizes greater than 10MB. Recommended to fetch details for such transactions using the REST endpoints using the published txid value.

#### Mainnet URLs

{% tabs %}
{% tab title="BSV" %}

```
wss://socket-v2.whatsonchain.com/websocket/mempool?format=<format>
```

{% endtab %}
{% endtabs %}

{% code title="Testnet URL (BSV)" %}

```
wss://socket-v2-testnet.whatsonchain.com/websocket/mempool?format=<format>
```

{% endcode %}

{% code title="Example Response" %}

```json
{
  "channel": "woc:mempoolTx:json",
  "pub": {
    "data": {
      "txid": "0ec9f572dc98234b6ee8860a04beeaba824cb60741a5d11054dc15dc300fa666",
      "hash": "0ec9f572dc98234b6ee8860a04beeaba824cb60741a5d11054dc15dc300fa666",
      "size": 170193,
      "version": 1,
      "locktime": 0,
      "vin": [
        {
          "n": 0,
          "txid": "181cb20e80d333d87aeedf1aa3aebc5b884ef3f68d14401d6c2d5b12dc16ce71",
          "vout": 55403,
          "scriptSig": {
            "asm": "30440220... 0342494361ea8...",
            "hex": "...",
            "isTruncated": false
          },
          "sequence": 4294967295
        }
      ],
      "vout": [
        {
          "value": 1e-8,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_DUP OP_HASH160 d5eb631a0e9d8c5728c68fc15b0e54754b29d83e OP_EQUALVERIFY OP_CHECKSIG",
            "hex": "...",
            "reqSigs": 1,
            "type": "pubkeyhash",
            "addresses": [
              "1LW6uqvMLPf2R62LFNnAizPjfQijE9vfsg"
            ],
            "isTruncated": false
          },
          "scripthash": "f70ee0566985..."
        },
        {
          "value": 1e-8,
          "n": 1,
          "scriptPubKey": { ... }
        },
        {
          "value": 0.00000654,
          "n": 5000,
          "scriptPubKey": {
            "asm": "OP_DUP OP_HASH160 38041fad29e8c1dce7fbcf3fc98b800a26dd2a4c OP_EQUALVERIFY OP_CHECKSIG",
            "hex": "...",
            "reqSigs": 1,
            "type": "pubkeyhash",
            "addresses": [
              "167BnGMU9cXjr5tDbJSBJJekKLMTrAQcry"
            ],
            "isTruncated": false
          },
          "scripthash": "8b55ee1a86..."
        }
      ],
      "vincount": 1,
      "voutcount": 5001,
      "voutvalue": 0.00005654000000000542
    }
  }
}
```

{% endcode %}

**URL Parameters**

| Parameter         | Description                                                                                                                  |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| format (optional) | `hex` (default) or `json`. If `hex`, the response will include transaction *hex* and metadata. If `json`, `hex` is excluded. |

## Confirmed Transactions

Receive confirmed transactions in real time.

* Confirmed transactions are collected from multiple nodes.

#### Mainnet URLs

{% tabs %}
{% tab title="BTC" %}

```
wss://socket-v2.whatsonchain.com/btc/websocket/confirmed
```

{% endtab %}
{% endtabs %}

{% code title="Example Response" %}

```json
{
  "channel": "woc:confirmedTx",
  "pub": {
    "data": {
      "txid": "0ec9f572dc98234b6ee8860a04beeaba824cb60741a5d11054dc15dc300fa666",
      "blockhash": "39b664939b6229f25274a74b0289ab81fcbf21f1d7cbffbc85b1470cacc8b80b",
      "blocktime": 1756463257,
      "blockheight": 912225
    }
  }
}
```

{% endcode %}

## Chain Stats

Receive common chain stats every 10 seconds.

#### Mainnet URLs

{% tabs %}
{% tab title="BSV" %}

```
wss://socket-v2.whatsonchain.com/websocket/stats
```

{% endtab %}
{% endtabs %}

{% code title="Testnet URL (BSV)" %}

```
wss://socket-v2-testnet.whatsonchain.com/websocket/stats
```

{% endcode %}

{% code title="Example Response" %}

```json
{
    "chainSummary": {
        "blocks": 892459,
        "bestblockhash": "0000000000000000051b71584570f8e5b335b821678c13161cf22b6ad34674c0",
        "difficulty": 59976456494.39465,
        "chainwork": "00000000000000000000000000000000000000000164d4254584d55761a28f20",
        "networkhashps": 409429675870798000,
        "circulatingSupply": 19851434.375,
        "mempoolSize": 16130,
        "mempoolBytes": 227959287,
        "mempoolUsage": 348692384,
        "exchangeRate": {
        "currency": "USD",
        "rate": "28.453333333333333"
        }
    },
    "txStatsSummary": [
        {
        "time": 1744643752,
        "txcount": 2093233133,
        "window_block_count": 144,
        "window_tx_count": 3012566,
        "window_interval": 85093,
        "txrate": 35.40321765597641
        },
        ...
    ],
    "latestBlocks": [
        {
        "hash": "0000000000000000051b71584570f8e5b335b821678c13161cf22b6ad34674c0",
        "confirmations": 1,
        "size": 140294551,
        "height": 892459,
        "version": 541065216,
        "versionHex": "20400000",
        "merkleroot": "3eee592dcd873f39bd98118582fc49b8d56e072ea28984041cd735111753edca",
        "txcount": 9723,
        "time": 1744643752,
        "mediantime": 1744641985,
        "nonce": 2459067680,
        "bits": "18125505",
        "difficulty": 59976456494.39465,
        "chainwork": "00000000000000000000000000000000000000000164d4254584d55761a28f20",
        "previousblockhash": "000000000000000004e776b40810b944b47a59ce4e8d9187eb05a351273116fe",
        "nextblockhash": "",
        "coinbaseTx": {
            "hex": "...",
            "txid": "7519a6fb28cd2796bf855b55f928c5effb0217cc0e98b935c646649bc3aba9e4",
            "hash": "7519a6fb28cd2796bf855b55f928c5effb0217cc0e98b935c646649bc3aba9e4",
            "size": 125,
            "version": 1,
            "locktime": 0,
            "vin": [
            {
                "n": 0,
                "coinbase": "032b9e0d04...",
                "sequence": 0,
                "minerInfo": {
                "name": "GorillaPool.com 🦍",
                "link": "https://GorillaPool.com",
                "type": "tag"
                }
            }
            ],
            "vout": [
            {
                "value": 3.1281591,
                "n": 0,
                "scriptPubKey": {
                "asm": "OP_DUP OP_HASH160 ad6684ded42b6a8edf8f5b64cec273c996039e02 OP_EQUALVERIFY OP_CHECKSIG",
                "hex": "...",
                "reqSigs": 1,
                "type": "pubkeyhash",
                "addresses": [
                    "1GoriLLa2bdsQ8fB1CA4JNkDX88mLqXf4u"
                ],
                "isTruncated": false
                },
                "scripthash": "c3ad9b15557df4604e5699d28b71ce8a8c479759472e6b9f252c93658c56b31a"
            }
            ],
            "blockhash": "...",
            "confirmations": 1,
            "time": 1744643752,
            "blocktime": 1744643752,
            "vincount": 1,
            "voutcount": 1,
            "voutvalue": 3.1281591
        },
        "totalFees": 0.0031590999999999703
        },
        {
        "hash": "000000000000000004e776b40810b944b47a59ce4e8d9187eb05a351273116fe",
        "confirmations": 2,
        "size": 270319069,
        "height": 892458,
        ...
        }
        ...
    ]
}
```

{% endcode %}

## Customized Events

If your application needs customized/filtered events via WebSockets, please let us know in the [WoC devs Telegram channel.](https://t.me/joinchat/FfE6-EjZhoTHwhDhZH6F-w)
