Last active
October 8, 2019 13:20
-
-
Save Hribek25/abf3e51864c32d2e0df5e20785d0cb36 to your computer and use it in GitHub Desktop.
Sending IOTA transaction in a single call: API call Send_transfer()
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_python.ipynb.html#00663E550ADF | |
# Requirement: PyOTA library (!pip install pyota) | |
import iota | |
from datetime import datetime | |
from pprint import pprint | |
MySeed = b"HGW9HB9LJPYUGVHNGCPLFKKPNZAIIFHZBDHKSGMQKFMANUBASSMSV9TAJSSMPRZZU9SFZULXKJ9YLAIUA" | |
TargetAddress1 = b"CXDUYK9XGHC9DTSPDMKGGGXAIARSRVAFGHJOCDDHWADLVBBOEHLICHTMGKVDOGRU9TBESJNHAXYPVJ9R9" | |
TargetAddress2 = b"CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RW" | |
NowIs = datetime.now() # get a actual date & time - just to have some meaningfull info | |
# preparing transactions | |
pt = iota.ProposedTransaction(address = iota.Address(TargetAddress1), # 81 trytes long address | |
message = iota.TryteString.from_unicode('Here comes a first message. Now is %s' % (NowIs)), | |
tag = iota.Tag(b'HRIBEK999IOTA999TUTORIAL'), # Up to 27 trytes | |
value = 0) | |
pt2 = iota.ProposedTransaction(address = iota.Address(TargetAddress2), # 81 trytes long address | |
message = iota.TryteString.from_unicode('Here comes a second message. Now is %s' % (NowIs)), | |
tag = iota.Tag(b'HRIBEK999IOTA999TUTORIAL'), # Up to 27 trytes | |
value = 0) | |
# besides the given attributes, library also adds a transaction timestamp | |
api = iota.Iota("https://nodes.thetangle.org:443") | |
print("Preparing/Broadcasting... Wait please...") | |
# the whole process initiated in a single call | |
FinalBundle = api.send_transfer(depth=3, | |
transfers=[pt,pt2], | |
min_weight_magnitude=14)['bundle'] # it returns a dictionary with a bundle object | |
#bundle is broadcasted, let's print it | |
print("\nGenerated bundle hash: %s" % (FinalBundle.hash)) | |
print("\nTail Transaction in the Bundle is a transaction #%s." % (FinalBundle.tail_transaction.current_index)) | |
print("\nList of all transactions in the bundle:\n") | |
for txn in FinalBundle: | |
pprint(vars(txn)) | |
print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment