This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from lzpap/fetch_data_tutorial
docs: Add 'Fetch Data' tutorial
- Loading branch information
Showing
2 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from iota import Iota, Address | ||
from iota.codecs import TrytesDecodeError | ||
|
||
# Declare an API object | ||
api = Iota('https://nodes.devnet.iota.org:443', testnet=True) | ||
|
||
# Address to fetch data from | ||
# Replace with your random generated address from Tutorial 2. to fetch the data | ||
# that you uploaded. | ||
addy = Address(b'WWO9DRAUDDSDSTTUPKJRNPSYLWAVQBBXISLKLTNDPVKOPMUERDUELLUPHNT9L9YWBDKOLYVWRAFRKIBLP') | ||
|
||
print('Fetching data from the Tangle...') | ||
# Fetch the transaction objects of the address from the Tangle | ||
response = api.find_transaction_objects(addresses=[addy]) | ||
|
||
if not response['transactions']: | ||
print('Couldn\'t find data for the given address.') | ||
else: | ||
print('Found:') | ||
# Iterate over the fetched transaction objects | ||
for tx in response['transactions']: | ||
# data is in the signature_message_fragment attribute as trytes, we need | ||
# to decode it into a unicode string | ||
data = tx.signature_message_fragment.decode(errors='ignore') | ||
print(data) |