Created
September 14, 2018 13:53
-
-
Save makevoid/70221d129f44f0a7fb2c5950bf076d5e to your computer and use it in GitHub Desktop.
Try Bitcoin (Cash) ZeroMQ Api to retrieve and parse raw transactions (JS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const zmq = require('zeromq') | |
const BitcoinCashZMQDecoder = require('bitcoincash-zmq-decoder') | |
const decoder = new BitcoinCashZMQDecoder("mainnet") | |
const subscriber = zmq.socket("sub") | |
const host = 'tcp://34.245.188.100:28332' | |
subscriber.subscribe("") // subscribe to all | |
const parseTransaction = (data) => { | |
const tx = decoder.decodeTransaction(data) | |
console.log( tx ) | |
} | |
subscriber.on("message", function (topic, data) { | |
topic = topic.toString() | |
data = data.toString('hex') | |
console.log(topic, data) | |
if (topic == "rawtx") { | |
parseTransaction(data) | |
} | |
if (topic == "rawblock") { | |
console.log("got a new block!") | |
} | |
}) | |
subscriber.connect(host) | |
// package.json | |
// | |
// { | |
// "dependencies": { | |
// "bitcoin-core": "^2.0.0", | |
// "bitcoincash-zmq-decoder": "^0.1.5", | |
// "bitcoincashjs": "^0.1.10", | |
// "insight-client": "^0.1.0", | |
// "zeromq": "^4.6.0" | |
// }, | |
// "scripts": { | |
// "start": "node try-btczmq" | |
// } | |
// } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment