Skip to content

Instantly share code, notes, and snippets.

Embed
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 https://hribek25.github.io/IOTA101/
// Complete description and story behind the snippet is available at: https://hribek25.github.io/IOTA101/Allchapters_csharp.ipynb.html#696A395DC61B
// 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 = "https://nodes.thetangle.org:443";
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
Console.WriteLine(
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
You can’t perform that action at this time.