Initialize IOTA repository

First, we need to initialize our main repository object. We can do that by typing:

var repository = IotaRepositoryFactory.Create("https://altnodes.devnet.iota.org");

Easy, right? Now we have our repository object that is going to take care of all the communication between us and the IRI.

If you are connected to a known IRI and you are sure that the node is stable for most cases, connecting like this is just fine. But sometimes there are cases where you need to have a fall back mechanism in case the node you are connected to fails, goes offline or is not in sync with the rest of the network. A solution can be carried out as follows:

var IRI_Nodes = new List<string>() {
    "https://altnodes.devnet.iota.org",
    "https://nodes.devnet.thetangle.org:443/",
    "https://nodes.devnet.iota.org:443/",
};
var repository = IotaRepositoryFactory.CreateWithFallback(IRI_Nodes);

As you can see in the above picture, we have a list of IRIs instead of just a single one. In case a node times out (5 seconds by default) or is unresponsive, it will automatically try to connect to the next node. The behavior is similar to a circuit breaker.

Last updated