Syscoin + ZMQ + Node.js = Realtime Blockchain Updates!

  • zeromq.jpg

Realtime Updates from the Syscoin Blockchain

You can use the ZMQ topic message queues in Syscoin to receive realtime updates for your application. Using in conjunction with syscoin-core to blockchain-enable your applications in no time.

Syscoin Configuration

Make sure to enable the ZMQ listeners in your syscoin.conf file and restart syscoind or Syscoin Core Qt.

[remote_content url="https://gist.githubusercontent.com/doublesharp/bacf7f9ac1ff15dccc1acffe49f989e9/raw/syscoin.conf" decode_atts="true" htmlentities="true"]

Create ZMQ Client

You will need to npm install the module zeromq.

const zeromq = require('zeromq');

const subscriber = zeromq.socket('sub');
subscriber.on('message', async (topic, message) => {
  topic = topic.toString('utf8');
  message = message.toString('utf8')
  const alias = JSON.parse(message);
  console.log(JSON.stringify(alias, null, 2));
});

// connect to message producer
subscriber.connect('tcp://127.0.0.1:3030');
subscriber.subscribe('aliasrecord');
console.log('subscribed to syscoin topic aliasrecord');

Run your script with the following:

> node zmq-client.js 
subscribed to syscoin topic aliasrecord
{
  "_id": "gldm1",
  "address": "SRxK2GjfzTrm8z5PgCtLKzheN5ebd5kN8f",
  "expires_on": 1590601936,
  "encryption_privatekey": "",
  "encryption_publickey": ""
}
{
  "_id": "elatte",
  "address": "Sd8JMHxtuFVSVJN2V51M27S6MkBBMjgjHY",
  "expires_on": 1559077278,
  "encryption_privatekey": "",
  "encryption_publickey": ""
}
{
  "_id": "primitive7",
  "address": "Sk7q3kZcttBNVkUwpMXU59yQf9Pco4sAAJ",
  "expires_on": 1558656041,
  "encryption_privatekey": "",
  "encryption_publickey": ""
}
{
  "_id": "primitive9",
  "address": "SYKff6VzkrzmSn9tL3zZE7FmV2dGFSKfxs",
  "expires_on": 1558656041,
  "encryption_privatekey": "",
  "encryption_publickey": ""
}
// ....

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *