https://github.com/exodusmovement/bitcoind-zmq
Get ZMQ notifications from bitcoin-like coins
https://github.com/exodusmovement/bitcoind-zmq
bitcoind btc coin crypto js nodejs notifications zmq
Last synced: 6 months ago
JSON representation
Get ZMQ notifications from bitcoin-like coins
- Host: GitHub
- URL: https://github.com/exodusmovement/bitcoind-zmq
- Owner: ExodusMovement
- License: mit
- Created: 2018-10-31T18:21:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-02-12T08:40:53.000Z (over 3 years ago)
- Last Synced: 2024-10-29T00:42:53.757Z (12 months ago)
- Topics: bitcoind, btc, coin, crypto, js, nodejs, notifications, zmq
- Language: JavaScript
- Size: 74.2 KB
- Stars: 20
- Watchers: 33
- Forks: 7
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# bitcoind-zmq
[](https://www.npmjs.com/package/bitcoind-zmq)

[](https://standardjs.com)> 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](https://github.com/bitcoin/bitcoin/blob/master/doc/zmq.md).
> bitcoind -zmqpubhashtx=tcp://127.0.0.1:28332 -zmqpubhashblock=tcp://127.0.0.1:28332
## Usage example
```javascript
const BitcoindZmq = require('bitcoind-zmq')const opts = { maxRetry: 20 }
const btcd = new BitcoindZmq({
// topic:
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
})btcd.on('hashtx', (hash) => {
// hash
})btcd.on('rawblock', (block) => {
// block
})btcd.on('rawtx', (tx) => {
// tx
})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({...}, )` 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(, )`: Add a `topic -> zmq node` pair (ex. `.add('hashtx', 'tcp://127.0.0.1:28333')`).
- `.on(, )`: the event name could be a [EventEmitter2](https://github.com/EventEmitter2/EventEmitter2) pattern with namespaces (ex. `.on('connect:hashtx', () => console.log('watching hashtx'))`).
- `.connect()`: *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()`: 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