Skip to content

Instantly share code, notes, and snippets.

@Hribek25
Hribek25 / IOTA101_0FF479CB6C0A.py
Last active September 24, 2019 10:30
Generating IOTA addresses from a seed: API call Get_new_addresses()
# 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#0FF479CB6C0A
# Requirement: PyOTA library (!pip install pyota)
import iota
from pprint import pprint
# For this particular task the Node URL is not important as it will not be contacted at all
# However it has to be well-formatted URI
NodeURL = "https://nodes.thetangle.org:443"
@Hribek25
Hribek25 / IOTA101_65788F1C3FCB.py
Last active September 24, 2019 10:30
Generating a seed: IOTA-facing-library-based approach
# 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#65788F1C3FCB
# Requirement: PyOTA library (!pip install pyota)
from iota.crypto.types import Seed #importing PyOTA library to interact with
NewSeed = Seed.random()
print(NewSeed)
print("Length: %s" % len(NewSeed))
@Hribek25
Hribek25 / IOTA101_67D98D069B61.py
Last active September 24, 2019 10:30
Generating a seed: a general approach
# 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#67D98D069B61
import random
chars=u'9ABCDEFGHIJKLMNOPQRSTUVWXYZ' #27 characters - max number you can express by one Tryte - do you remember?
rndgenerator = random.SystemRandom() #cryptographically secure pseudo-random generator
NewSeed = u''.join(rndgenerator.choice(chars) for _ in range(81)) #generating 81-chars long seed. This is Python 3.6+ compatible
print(NewSeed)
print("Length: %s" % len(NewSeed))
@Hribek25
Hribek25 / IOTA101_696A395DC61B.py
Last active September 24, 2019 10:30
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
@Hribek25
Hribek25 / IOTA101_3BB8C879CCAE.py
Last active September 24, 2019 10:30
Conversion: trytes and trits
# 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#3BB8C879CCAE
# Requirement: PyOTA library (!pip install pyota)
import iota #importing PyOTA library to interact with
from pprint import pprint
TrytesAsBytes = b"YZJEATEQ9JKLZ" # some data encoded in Trytes (byte string in Python, not unicode string)
Trytes = iota.TryteString(TrytesAsBytes) # initializing TryteString type from the PyOTA library - great help while dealing with Trytes/Trits, etc.
pprint(Trytes) # getting the same data however using TryteString type of PyOTA library