I am using one command tangle. The tangle is running on Ubuntu machine. From the list of APIs given for IRI node, I'm trying to broadcast a transaction. For this, the first step is to get getTransactionsToApprove which returns trunkTransaction and branchTransaction and I have to assign that value to attachToTangle API. I am getting the correct output from getTransactionsToApprove API:
{'trunkTransaction': 'NTCYZTAJTVJIAQW9JXUJCACYPHNMESWGWTANQQZSLGHQTKWGDOYHAHBETUXKNAMMWYDTILDWLPQTOX999', 'branchTransaction': 'NTCYZTAJTVJIAQW9JXUJCACYPHNMESWGWTANQQZSLGHQTKWGDOYHAHBETUXKNAMMWYDTILDWLPQTOX999', 'duration': 2}
The problem is when I am assigning those values to attachToTangle API, I'm getting this error:
HTTP Error 500: Internal Server Error
My code is:
import urllib.request
import urllib.parse
import json
import requests
trytes = "hello world!"
url="http://mydnsname:14265"
headers = {
'Content-Type': 'application/json',
"Accept": "application/json",
'X-IOTA-API-Version': '1'
}
#get transactions
command = {
"command": "getTransactionsToApprove",
"depth": 4
}
data= json.dumps(command).encode("utf-8")
request = urllib.request.Request(url, data, headers)
try:
returnData = urllib.request.urlopen(request).read()
jsonData = json.loads(returnData)
print (jsonData)
except urllib.error.URLError as e:
ResponseData = e.reason
print (e)
#attach to tangle
command = {
"command": "attachToTangle",
"trunkTransaction": jsonData['trunkTransaction'],
"branchTransaction": jsonData['branchTransaction'],
"minWeightMagnitude": 9,
"trytes": trytes
}
data= json.dumps(command).encode("utf-8")
request = urllib.request.Request(url, data, headers)
try:
returnData = urllib.request.urlopen(request).read()
jsonData = json.loads(returnData)
print (jsonData)
except urllib.error.URLError as e:
ResponseData = e.reason
print (e)
Any help is much appreciated.
trytes
variable has to be a whole transaction encoded as trytes (so not only the text payload, but also address, amount, bundle hash etc...). Just passing random ASCII characters as trytes is not going to work.pyota
tag, as this code is not using the PyOTA library (github.com/iotaledger/iota.py) — although I recommend you give it a try; it might make things easier 😺