Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Basic node interaction: API call Get_node_info()
// The snippet is a part of the IOTA Developer Essentials project. You can reach it at
// Complete description and story behind the snippet is available at:
// Requirement: Tangle.Net library (!nuget install Tangle.Net)
// Requirement: Newtonsoft Json library (!nuget install Newtonsoft.Json)
// Requirement: RestSharp library (Simple REST and HTTP API Client used with Tangle.Net) (!nuget install RestSharp)
#r "Tangle.Net.dll"
#r "Newtonsoft.Json.dll"
#r "RestSharp.dll"
using Tangle.Net.Repository;
using Newtonsoft.Json;
using RestSharp;
var NodeURL = "";
var repo = new RestIotaRepository(new RestClient(NodeURL)); // ctor initialization of the Tangle.Net library
var nodeInfo = repo.GetNodeInfo(); // Getting information about the current node
Console.WriteLine(JsonConvert.SerializeObject(nodeInfo, Formatting.Indented)); //Result is printed in JSON notation
// Basic check whether node is in sync or not
// Elementary rule is that "latestMilestoneIndex" should equal to "latestSolidSubtangleMilestoneIndex" or be very close
Math.Abs(nodeInfo.LatestMilestoneIndex - nodeInfo.LatestSolidSubtangleMilestoneIndex) > 3 ?
"Node is probably not synced!" : "Node is probably synced!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment