IOTA, Distributed ledgers and C#
  • Abstract
  • Introduction
  • What is IOTA?
  • Development
    • Install Tangle-net NuGet
    • Initialize IOTA repository
    • Node control
    • Basics
      • Seeds and addresses
      • Sending transactions
    • ZMQ
  • Resources and further reading
  • Contact
Powered by GitBook
On this page

Was this helpful?

  1. Development

ZMQ

PreviousSending transactionsNextResources and further reading

Last updated 5 years ago

Was this helpful?

is a high-performance asynchronous messaging library. It can be used to hook up to a node and listen to events. This allows us to listen to a variety of events such as: all transactions coming into the node, all confirmed transactions, etc. The full list of events can be found .

In order to use it we first need to install Tangle.Net.Zmq NuGet. Furthermore, if we want to hook up onto a node, the node must have ZMQ enabled . Here is an simple example of how to listen to all incoming transactions:

// Subscribe to transactions event
ZmqIriListener.Transactions += (sender, eventArgs) =>
{
    Console.WriteLine("-----------------------");
    Console.WriteLine(eventArgs.Transaction.Hash);
    Console.WriteLine(eventArgs.Transaction.Address);
};

// Start listening to the event type (use MessageType.All) to subscribe to all events
var tokenSource = ZmqIriListener.Listen("tcp://node_url", MessageType.All);

// Listen for 60 seconds
var stopwatch = new Stopwatch();
stopwatch.Start();
while (stopwatch.ElapsedMilliseconds < 600000)
{
    Thread.Sleep(100);
}
// Cancel the thread
tokenSource.Cancel();

We have to be careful because listening to everything is very expensive. That is why we have the MessageType enum. The MessageType is the name of the event as IRI knows it. This means that once we listen to a certain MessageType we will only have the corresponding C# event occurring.

ZMQ is a very useful tool as it allows us to monitor the Tangle in real time. We can monitor transactions, specific addresses and a lot more.

ZeroMQ
here