Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
bitcoind-zmq
Advanced tools
Get ZMQ notifications from bitcoind-like coins
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
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)
})
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=bitcoind-zmq
MIT
FAQs
Get ZMQ notifications from bitcoind-like coins
We found that bitcoind-zmq demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.