Skip to content

Instantly share code, notes, and snippets.

@Hribek25
Last active October 8, 2019 13:20
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/de919df95413205f1c7d03863be85273 to your computer and use it in GitHub Desktop.
Save Hribek25/de919df95413205f1c7d03863be85273 to your computer and use it in GitHub Desktop.
Sending IOTA transaction in more granular way: API calls Prepare_transfer() and Send_transfer()
# 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#07CFD43B146C
# 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")
# Creating bundle, preparing inputs and finalizing bundle. It returns trytes of prepared TXs
Trytes = api.prepare_transfer(transfers=[pt,pt2])
print("Almost prepared bundle - tips and POW are still missing")
pprint(Trytes)
print("\nSearching for tips and performing POW... Wait please...")
Result = api.send_trytes(trytes=Trytes["trytes"],
depth=3) # Searching for tips, performing POW and broadcasting
print("Bundle was broadcasted.")
print("\nFinal transactions were returned - including nonce (POW)")
pprint(Result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment