Last active
September 24, 2019 10:30
-
-
Save Hribek25/4f8ed43eb14b79d8a4cda304e9817a74 to your computer and use it in GitHub Desktop.
Basic node interaction: API call Get_node_info()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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