<p>I am trying to use the zeromq api for bitcoind to get rawblock but its not working with the code I've provided below. I am able to get <code>hashtx</code> and <code>rawtx</code> if I remove the filter but not <code>hashblock</code> and <code>rawblock</code>. Not sure if this is an important detail or not but my bitcoind is still syncing so I'm not sure if those topics are only triggered when bitcoind has synced up.</p>
<pre><code>// Implementation of ZeroMQ in node.js.
// From the maintainers of the ZeroMQ protocol.
var zmq = require(&quot;zeromq&quot;);

// Create a subscriber socket.
const sock = new zmq.Subscriber();
var addr = &quot;tcp://127.0.0.1:28332&quot;;

// Initiate connection to TCP socket.
sock.connect(addr);

// Subscribe to receive messages for a specific topic.
// This can be &quot;rawblock&quot;, &quot;hashblock&quot;, &quot;rawtx&quot;, or &quot;hashtx&quot;.
sock.subscribe(&quot;rawblock&quot;);

(async () =&gt; {
  for await (const [topic, msg] of sock) {
    console.log(topic.toString())
  }
})();
</code></pre>
<p>My <code>bitcoin.conf</code> file looks like:</p>
<pre><code>server=1
txindex=1

# [zeromq]
zmqpubhashblock=tcp://127.0.0.1:28332
zmqpubhashtx=tcp://127.0.0.1:28332
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28332
</code></pre>

CC BY-SA 4.0
2020-08-25T19:05:00.167Z
What sort of error messages are you getting? And do you see anything relevant in your `debug.log` file from bitcoind?
torkel
CC BY-SA 4.0
2020-08-25T19:41:31.937Z
@torkel no error messages, just not receiving the messages coming from my node when `rawblock` is being used. If I try to get `rawtx` or `hashtx` it works fine which is weird. I didn't find anything in the `debug.log` either. 

When I run `bitcoin-cli getzmqnotifications` I get the following as expected:

`[{ "type": "pubrawblock", "address": "tcp://127.0.0.1:28332", "hwm": 1000 }, ... ]`
Kevin Kelbie
CC BY-SA 4.0
2020-08-26T01:54:06.317Z
ZMQ notifications for new blocks only start when bitcoind is in sync with the network.
Pieter Wuille
<bitcoin-core><bitcoind><javascript><zeromq>
bitcoind: How to get rawblock data with ZeroMQ
Kevin Kelbie
# bitcoind: How to get rawblock data with ZeroMQ

(Asked by: username_0 on 2020-08-25)

I am trying to use the zeromq api for bitcoind to get rawblock but its not working with the code I've provided below. I am able to get hashtx and rawtx if I remove the filter but not hashblock and rawblock. Not sure if this is an important detail or not but my bitcoind is still syncing so I'm not sure if those topics are only triggered when bitcoind has synced up.
// Implementation of ZeroMQ in node.js.
// From the maintainers of the ZeroMQ protocol.
var zmq = require("zeromq");

// Create a subscriber socket.
const sock = new zmq.Subscriber();
var addr = "tcp://127.0.0.1:28332";

// Initiate connection to TCP socket.
sock.connect(addr);

// Subscribe to receive messages for a specific topic.
// This can be "rawblock", "hashblock", "rawtx", or "hashtx".
sock.subscribe("rawblock");

(async () => {
  for await (const [topic, msg] of sock) {
    console.log(topic.toString())
  }
})();

My bitcoin.conf file looks like:
server=1
txindex=1

# [zeromq]
zmqpubhashblock=tcp://127.0.0.1:28332
zmqpubhashtx=tcp://127.0.0.1:28332
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28332

**Tags:** bitcoin-core, bitcoind, javascript, zeromq

> **Comments:**
> **username_1**: What sort of error messages are you getting? And do you see anything relevant in your `debug.log` file from bitcoind?  
> **username_0**: @username_1 no error messages, just not receiving the messages coming from my node when `rawblock` is being used. If I try to get `rawtx` or `hashtx` it works fine which is weird. I didn't find anything in the `debug.log` either.   When I run `bitcoin-cli getzmqnotifications` I get the following as expected:  `[{ "type": "pubrawblock", "address": "tcp://127.0.0.1:28332", "hwm": 1000 }, ... ]`  
> **username_2**: ZMQ notifications for new blocks only start when bitcoind is in sync with the network.  

---

## 0 answers

