2

I am trying to use ZMQ feeds to monitor IRI nodes and addresses, but I am having trouble obtaining the "Message" in text and/or JSON.

I am using this code:

let zmq = require('zeromq')
let sock = zmq.socket('sub')
sock.connect('tcp://node.deviceproof.org:5556')
sock.subscribe('tx_trytes')
sock.subscribe('tx')
sock.on('message', async msg => {
    const data = msg.toString().split(' ') // Split to get topic & data
    if (data[0] === "tx") {
        console.log('Raw Object:', data[3])
    } else if (data[0] === "tx") {
        console.log("Transaction:", data[1]);
    }
})

I can get the "Raw transaction object" from this line,

console.log('Raw Object:', data[3])

But it comes in as trytes and I am only interested in the signatureMessageFragment (https://docs.iota.org/docs/dev-essentials/0.1/references/structure-of-a-transaction), which I would like in JSON and/or text. The IOTA docs on ZMQ events do not have any subscription topics to get what I am looking for (https://docs.iota.org/docs/node-software/0.1/iri/references/zmq-events).

Maybe I am missing something? I thought about bringing in the trytes and converting them to text, but I cannot find a IOTA API call for that in the IOTA JS library (https://github.com/iotaledger/iota.js/).

Any help, or suggestions would be much appreciated, and if you need any clarification on my question feel free to ask.

I believe this question is somewhat related to mine, ZeroMQ subscription to address not working

Antonio Nardella
  • 1,074
  • 5
  • 17
W. Churchill
  • 141
  • 3

2 Answers2

0

The way you are going about it is correct. There is no topic for just signatureMessageFragment.

In order to convert the proper trytes to text: https://www.npmjs.com/package/@iota/converter#module_converter.trytesToAscii

whomaniac
  • 131
  • 1
0

Here is a way you could get this data:

const zmq = require('zeromq');
const TransactionConverter = require('@iota/transaction-converter');
const Converter = require('@iota/converter');

let sock = zmq.socket('sub');

sock.connect('tcp://node.deviceproof.org:5556');
sock.subscribe('tx_trytes');

sock.on('message', async msg => {
    // Split to get topic & data
    const data = msg.toString().split(' ');

    // Convert the transaction trytes to an object
    let txObj = TransactionConverter.asTransactionObject(data[1]);

    // Get the signatureMessageFragment
    let signatureMessageFragment = txObj.signatureMessageFragment

    // Remove the last tryte so that the the converter doesn't complain about uneven trytes
    console.log(Converter.trytesToAscii(signatureMessageFragment.substring(0, signatureMessageFragment.length - 1)));

});

You'll need to install the following packages:

  • transaction-converter to be able to convert the transaction trytes to a transaction object
  • converter to be able to convert the signatureMessageFragment trytes to ASCII characters
Jake Cahill
  • 361
  • 1
  • 4