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_javascript.ipynb.html#696A395DC61B
// Requirement: IOTA Javascript Library (!npm install iota.lib.js)
var IOTA = require('../../node_modules/iota.lib.js/lib/iota'); // load iota.lib.js
// # ctor initialization of the iota.lib.js library
var iota = new IOTA({
'provider': 'https://nodes.thetangle.org:443'
});
// basic API call to double check health conditions
iota.api.getNodeInfo(function (error, success) {
if (error) {
// unable to perform getNodeInfo call
console.error(error);
} else {
// result is printed out
console.log(success);
// Basic check whether node is in sync or not
// Elementary rule is that "latestMilestoneIndex" should equal to "latestSolidSubtangleMilestoneIndex" or be very close
if (Math.abs(success['latestMilestoneIndex'] - success['latestSolidSubtangleMilestoneIndex']) > 3) {
console.log('\r\nNode is probably not synced!');
} else {
console.log('\r\nNode 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.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.