Skip to main content

ZMQ Notification Types

Bitcoin Core provides five ZMQ notification types for monitoring blockchain and mempool events in real-time.

Message Format

All ZMQ messages are multipart messages with three components:
  • Topic: String identifying the notification type (e.g., “hashtx”, “rawblock”)
  • Body: Binary message payload (format varies by topic)
  • Sequence Number: 4-byte little-endian unsigned integer (distinct per topic)
All transaction and block hashes are in reversed byte order (same format as RPC interface and block explorers).

hashtx - Transaction Hash Notifications

Configuration

Message Format

When Triggered

Notifies about transactions in two scenarios:
  1. When a transaction is added to the mempool
  2. When a block arrives containing the transaction
Transactions may be published multiple times: once when entering the mempool and again in each block that includes them.

Example Client (Python)

hashblock - Block Hash Notifications

Configuration

Message Format

When Triggered

Notifies when the chain tip is updated.
AssumeUTXO: When assumeutxo is active, this notification is not issued for historical blocks connected to the background validation chainstate.

Reorganization Behavior

During a blockchain reorganization:
  • Only the new tip is notified
  • Intermediate blocks are not individually announced
  • Clients must retrieve the chain from their last known block to the new tip

Example Client (Python)

rawtx - Raw Transaction Notifications

Configuration

Message Format

When Triggered

Same trigger conditions as hashtx:
  1. Transaction added to mempool
  2. Block arrives containing the transaction

Example Client (Python)

rawblock - Raw Block Notifications

Configuration

Message Format

When Triggered

Same trigger conditions as hashblock - when the chain tip is updated.

Example Client (Python)

sequence - Mempool and Block Sequence

Configuration

Message Format

The sequence topic provides a total ordering of all mempool and block events.

Block Connect/Disconnect

  • ‘C’: Block with this hash connected
  • ‘D’: Block with this hash disconnected

Mempool Add/Remove

  • ‘A’: Transaction with this hash added to mempool
  • ‘R’: Transaction with this hash removed from mempool (non-block reason)

Mempool Sequence Number

The 8-byte mempool sequence number provides total ordering of mempool events. This is separate from the ZMQ message sequence number.
Use the sequence topic when you need complete visibility into block reorganizations and mempool changes.

Example Client (Python)

Multi-Topic Subscriber

Subscribe to multiple topics on a single socket:

Async Example (Python asyncio)

Based on Bitcoin Core’s contrib/zmq/zmq_sub.py:

Best Practices

Error Handling

Sequence Gap Detection

Multiple Endpoints

Configure different topics on different endpoints for load distribution:

ZMQ Overview

Learn about the ZMQ notification system architecture

RPC Reference

Explore Bitcoin Core’s JSON-RPC interface