Skip to content

Instantly share code, notes, and snippets.

@Hribek25
Last active September 24, 2019 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hribek25/90c13e2017244c86360729c1325b5b32 to your computer and use it in GitHub Desktop.
Save Hribek25/90c13e2017244c86360729c1325b5b32 to your computer and use it in GitHub Desktop.
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