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:- When a transaction is added to the mempool
- When a block arrives containing the transaction
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 ashashtx:
- Transaction added to mempool
- Block arrives containing the transaction
Example Client (Python)
rawblock - Raw Block Notifications
Configuration
Message Format
When Triggered
Same trigger conditions ashashblock - when the chain tip is updated.
Example Client (Python)
sequence - Mempool and Block Sequence
Configuration
Message Format
Thesequence 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’scontrib/zmq/zmq_sub.py:
Best Practices
Error Handling
Sequence Gap Detection
Multiple Endpoints
Configure different topics on different endpoints for load distribution:Related Resources
ZMQ Overview
Learn about the ZMQ notification system architecture
RPC Reference
Explore Bitcoin Core’s JSON-RPC interface