options_test.py
import asyncio, time from peaq_robot import PeaqRobot from peaq_robot.types import TxOptions, ConfirmationMode sdk = PeaqRobot() # FAST (string tx-hash) tx1 = sdk.store.add_data(f"OPT_FAST_{int(time.time())}", {"t": int(time.time())}) print("FAST:", tx1) # FINAL (awaitable finalize) def on_status(s): try: print(s.model_dump()) except Exception: print({"status": str(s.status), "hash": s.hash}) res = sdk.store.add_data( f"OPT_FINAL_{int(time.time())}", {"t": int(time.time())}, tx_options=TxOptions(mode=ConfirmationMode.FINAL), on_status=on_status, ) final_receipt = asyncio.run(res.finalize) print("FINALIZED:", str(final_receipt)[:180])
pip install -U peaq-robotics-sdk
FAST: 0x3b7f...e1 {'status': <TransactionStatus.BROADCAST: 'BROADCAST'>, 'hash': '0x3b7f...e1', ...} {'status': <TransactionStatus.IN_BLOCK: 'IN_BLOCK'>, 'hash': '0x3b7f...e1', ...} {'status': <TransactionStatus.FINALIZED: 'FINALIZED'>, 'hash': '0x3b7f...e1', ...} FINALIZED: {'extrinsic_hash': '0x3b7f...e1', 'success': True, 'events': [...]}