主旨: Iota python 套件範例
更新日期: 2022-02-25
版本: V1
作者: Ya-Sheng Chen (Rock)
IOTA
是第三代公開無權限(permissionless) 分散式帳本, 其網路所使用的為有向無環圖( Directed Acyclic Graph, 簡稱 ) , IOTA 稱呼此 DAG 為「Tangle
」
無需交易費、 速度更快、 更具擴充性的交易平台, 更在於加強物聯網( Internet of Things),紀錄和執行物聯網生態中不同設備間的資料傳輸, 提供一個人類和電腦可以交換資料的特殊網絡。
團隊運用分散式帳本技術, 針對物聯網打造了創新的 Tangle 網路, 與區塊鏈一樣意圖創立一個去中心化的世界,Tangle
是IOTA
開發團隊基於有向無環圖(DAG) 技術所打造的去中心化網路系統, Tangle 並不是區
塊鏈, 因為 Tangle
的世界中既沒有鏈, 沒有區塊, 也沒有礦工。
● 擴展性 (Scalability) ● 去中心化 (Decentralisation) ● 無交易手續費 (No transaction fees) ● 抵抗量子計算 (Quantum computing protection)
- 依自己Python版本, 下載官方 python-client 套件.zip檔案,並解壓縮至您的project 資料夾
- 進入您需要安裝套件的python 環境
cd ./Document/project/iota_test
source ./venv/bin/activite
- 安裝套件
pip install iota_client_python-0.2.0_alpha.3-cp38-abi3-linux_x86_64.whl
- 完成
- 檢視安裝套件是否完成
pip list
- 檢視安裝套件是否完成
Package Version
-------------------------- -------
iota-client-python 0.2.0a3
import iota_client
# 預設
client = iota_client.Client()
# 自定義<option>
client = iota_client.Client(network='devnet',
nodes_name_password=[['https://api.lb-1.h.chrysalis-devnet.iota.cafe']])
net_type
= [deafult="devnet"
,"mainnet"
] # 主網與測試網node_addr
= 預設測試網址https://api.lb-1.h.chrysalis-devnet.iota.cafe
進行算力並上傳交易使用的節點地址。
client.get_info()
response
{
"nodeinfo":{
"name":"HORNET",
"version":"0.6.0-alpha",
"is_healthy":true,
"network_id":"testnet7",
"bech32_hrp":"atoi",
"min_pow_score":4000.0,
"messages_per_second":27.3,
"referenced_messages_per_second":34.5,
"referenced_rate":126.37362637362637,
"latest_milestone_timestamp":1618133322,
"latest_milestone_index":33602,
"confirmed_milestone_index":33602,
"pruning_index":16086,
"features":[
"PoW"
]
},
"url":"https://api.hornet-0.testnet.chrysalis2.com"
}
client.get_health()
>> True
- index <str> = 為你的資訊設定index名稱,之後可透過此index 於 區塊鏈瀏覽器查詢這筆資訊
- data_str <str>= 需要上傳的資訊
idx_name = "Rock_1"
mssg = "hello world 1"
# sending message
result = client.message(index=idx_name, data_str=mssg)
- 可於 iota tangle explorer 查詢 透過切換 [
mainnet
,devnet
] 查詢主網或測試網上的上鏈資訊
import iota_client
try:
# init connect
client = iota_client.Client()
# check node health
is_health = client.get_health()
if not is_health:
raise ValueError('node is not healthy, please check node is on, or change node address')
# prepare index and mssg
for i in range(2):
idx_name = f'Rock'
mssg = f'hello world {i}'
# send message
client.message(index=idx_name, data_str=mssg)
except ValueError as ve:
print(ve)
except Exception as e:
print(e)
-
IOTA 1.5
Chrysalis
-
IOTA 1.0
-
IOTA 1.0 -
hornet<full node>
-
Chronicle<permanode>