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/f9d9df97a46a05967c10aa5b9640394b to your computer and use it in GitHub Desktop.
Save Hribek25/f9d9df97a46a05967c10aa5b9640394b 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_python.ipynb.html#696A395DC61B
# Requirement: PyOTA library (!pip install pyota)
import iota #importing PyOTA library to interact with
from pprint import pprint
NodeURL = "https://nodes.thetangle.org:443"
api=iota.Iota(NodeURL) # ctor initialization of the PyOTA library
result = api.get_node_info() # basic API call to double check health conditions
pprint(result) # result is printed out
# Basic check whether node is in sync or not
# Elementary rule is that "latestMilestoneIndex" should equal to "latestSolidSubtangleMilestoneIndex" or be very close
if abs(result['latestMilestoneIndex'] - result['latestSolidSubtangleMilestoneIndex']) > 3 :
print ("\r\nNode is probably not synced!")
else:
print ("\r\nNode is probably synced!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment