4

I am trying to develop an online application primarily in JavaScript. As I am aware, the only way to receive notifications for unconfirmed/mempool transactions as they appear on the network is to utilize the -zmqpubrawtx or -zmqpubhashtx commands in the startup of Bitcoin-Core. I have setup one of these values to be the example -zmqpubhashtx=tcp://127.0.0.1:28332

However, I am having a difficult time implementing this in any browser based JavaScript. The only library that is not based solely on Node.js is JSMQ which does not appear to support tcp:// as the socket type (apparently relies on JavaScripts WebSocket which only lets you use ws:// or wss://). I am trying to avoid online API usage such as blockchain.info, etc.

My question: Are there any other methods of receiving realtime unconfirmed transactions notifications (that don't belong to a specific wallet) and that doesn't rely on an external/online API? If there is no alternative, are there any known/reputable libraries available for ZeroMQ for JavaScript

1

If I understand this correctly, you're trying to communicate with Bitcoin Core through ZeroMQ directly from the browser. This is not possible.

The reason why JSMQ only supports Websockets (ws://) is that browsers don't allow you to use raw TCP sockets. The only protocols you can access from within the browser are HTTP(S), Websockets, and WebRTC (which is still not supported everywhere).

In other words: the browser won't let you communicate directly through ZeroMQ.

If you don't want to rely on an external API, then you can always write your own and run it on the same server/computer where you are currently running Bitcoin Core. This software should receive updates from the Bitcoin node through ZeroMQ, and send them to the browser via websockets.

As long as it supports websockets or HTTP(S) you'll be able to connect to it from within your browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.