Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitcoind-zmq

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcoind-zmq

Get ZMQ notifications from bitcoind-like coins

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

bitcoind-zmq

NPM Version node JavaScript Style Guide

Get ZMQ notifications from bitcoind-like coins

Install

npm install --save bitcoind-zmq

And make sure to run bitcoind or whatever btc-like coin (that support zmq) with his zmq options.

bitcoind -zmqpubhashtx=tcp://127.0.0.1:28332 -zmqpubhashblock=tcp://127.0.0.1:28332

Usage example

const BitcoindZmq = require('bitcoind-zmq')

const opts = { maxRetry: 20 }

const btcd = new BitcoindZmq({
  // topic: <zmq node>
  hashtx: 'tcp://127.0.0.1:28332',
  hashblock: 'tcp://127.0.0.1:28332',
  rawtx: 'tcp://127.0.0.1:28334',
  rawblock: 'tcp://127.0.0.1:28334'
}, opts)

btcd.connect()

btcd.on('hashblock', (hash) => {
  // hash <Buffer ... />
})

btcd.on('hashtx', (hash) => {
  // hash <Buffer ... />
})

btcd.on('rawblock', (block) => {
  // block <Buffer ... />
})

btcd.on('rawtx', (tx) => {
  // tx <Buffer ... />
})

btcd.on('connect:*', (uri, type) => {
  console.log(`socket ${type} connected to ${uri}`)
})

btcd.on('retry:hashtx', (type, attempt) => {
  console.log(`hashtx, connect retry attempt: ${attempt}`)
})

btcd.on('error:*', (err, type) => {
  console.error(`${type} had error:`, err)
})

API

The BitcoindZMQ({...}, <opts>) Class accepts in his constructor topic -> zmq node pairs. The only option available is maxRetry the maximum n. of attempt to connect to a zmq node.

  • .add(<type>, <uri>): Add a topic -> zmq node pair (ex. .add('hashtx', 'tcp://127.0.0.1:28333')).
  • .on(<eventName>, <fn>): the event name could be a EventEmitter2 pattern with namespaces (ex. .on('connect:hashtx', () => console.log('watching hashtx'))).
  • .connect(<nodeType>): nodeType could be a String/Array of previously added topics to connect to. If none is provided it will connect to all the added nodes.
  • .disconnect(<nodeType>): disconnect from the given nodes or from all nodes if no argument is provided.

Also refer to the example for usage.

Bitcoind available events are these below. You can add new coins' events or get rid of those you don't need when instantiating the Class:

  • hashblock
  • hashtx
  • rawblock
  • rawtx

Reserved events and namespaces:

  • error:* event fired with Error
  • close:*: event fired with Error if any, and nodeType.
  • connect:*: event fired with Uri, nodeType.
  • retry:*: event fired with nodeType, attempt

example: error:* will catch every node error (error:hashblock, error:hashtx, and so on...)

Debug

DEBUG=bitcoind-zmq

License

MIT

Keywords

FAQs

Package last updated on 15 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc