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: A core module of IOTA Javascript Library (!npm install @iota/core)
var iotalib = require('@iota/core'); // loading iota.js core module. More info: https://github.com/iotaledger/iota.js/tree/next/packages/core
// composerAPI initialization of the iota.js library
var iota = iotalib.composeAPI({
'provider': 'https://nodes.thetangle.org:443'
});
// basic API call to double check health conditions
var promise = iota.getNodeInfo()
.then(info => {
console.log(info);
// 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(info['latestMilestoneIndex'] - info['latestSolidSubtangleMilestoneIndex']) > 3) {
console.log('\r\nNode is probably not synced!');
} else {
console.log('\r\nNode is probably synced!');
}
})
.catch(error => {
console.log('Request error: ${error.message}')
});
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.