From 448aaa63a70a7135e49297ded43d409182c6de93 Mon Sep 17 00:00:00 2001 From: nessshon Date: Thu, 19 Dec 2024 05:33:16 +0500 Subject: [PATCH] Update examples. --- examples/accounts/get_all_address_formats.py | 12 +++++++----- examples/accounts/get_info.py | 12 +++++++----- examples/accounts/get_transactions.py | 12 +++++++----- examples/nfts/get_by_collection.py | 12 +++++++----- examples/nfts/get_by_owner.py | 12 +++++++----- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/examples/accounts/get_all_address_formats.py b/examples/accounts/get_all_address_formats.py index 78a4c2c..7670f78 100644 --- a/examples/accounts/get_all_address_formats.py +++ b/examples/accounts/get_all_address_formats.py @@ -1,5 +1,5 @@ """Parse address and display in all formats.""" -from pytonapi import Tonapi +from pytonapi import AsyncTonapi # Enter your API key API_KEY = "" # noqa @@ -8,9 +8,9 @@ ACCOUNT_ID = "UQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqEBI" # noqa -def main(): - tonapi = Tonapi(api_key=API_KEY) - account = tonapi.utilities.parse_address(ACCOUNT_ID) +async def main() -> None: + tonapi = AsyncTonapi(api_key=API_KEY) + account = await tonapi.utilities.parse_address(ACCOUNT_ID) print(f"Raw form: {account.raw_form}") # output: 0:83dfd552e63729b472fcbcc8c45ebcc6691702558b68ec7527e1ba403a0f31a8 @@ -23,4 +23,6 @@ def main(): if __name__ == '__main__': - main() + import asyncio + + asyncio.run(main()) diff --git a/examples/accounts/get_info.py b/examples/accounts/get_info.py index 0720ac4..414facb 100644 --- a/examples/accounts/get_info.py +++ b/examples/accounts/get_info.py @@ -1,5 +1,5 @@ """Get account info.""" -from pytonapi import Tonapi +from pytonapi import AsyncTonapi # Enter your API key API_KEY = "" # noqa @@ -8,10 +8,10 @@ ACCOUNT_ID = "EQAUxYSo-UwoqAGixaD3d7CNLp9PthgmEZfnr6BvsijzJHdA" # noqa -def main(): +async def main() -> None: # Creating new Tonapi object - tonapi = Tonapi(api_key=API_KEY) - account = tonapi.accounts.get_info(account_id=ACCOUNT_ID) + tonapi = AsyncTonapi(api_key=API_KEY) + account = await tonapi.accounts.get_info(account_id=ACCOUNT_ID) print(f"Raw form: {account.address.to_raw()}") # output: 0:bede2955afe5b451cde92eb189125c12685c6f8575df922400dc4c1d5411cd35 @@ -30,4 +30,6 @@ def main(): if __name__ == '__main__': - main() + import asyncio + + asyncio.run(main()) diff --git a/examples/accounts/get_transactions.py b/examples/accounts/get_transactions.py index 9cf7ef4..a9cef38 100644 --- a/examples/accounts/get_transactions.py +++ b/examples/accounts/get_transactions.py @@ -1,5 +1,5 @@ """Get account transactions.""" -from pytonapi import Tonapi +from pytonapi import AsyncTonapi from pytonapi.utils import to_amount # Enter your API key @@ -9,9 +9,9 @@ ACCOUNT_ID = "EQAUxYSo-UwoqAGixaD3d7CNLp9PthgmEZfnr6BvsijzJHdA" # noqa -def main(): - tonapi = Tonapi(api_key=API_KEY) - result = tonapi.blockchain.get_account_transactions(account_id=ACCOUNT_ID, limit=1000) +async def main() -> None: + tonapi = AsyncTonapi(api_key=API_KEY) + result = await tonapi.blockchain.get_account_transactions(account_id=ACCOUNT_ID, limit=1000) for transaction in result.transactions: print(f"Value nanoton: {transaction.in_msg.value}") @@ -26,4 +26,6 @@ def main(): if __name__ == '__main__': - main() + import asyncio + + asyncio.run(main()) diff --git a/examples/nfts/get_by_collection.py b/examples/nfts/get_by_collection.py index 99581dd..38cc336 100644 --- a/examples/nfts/get_by_collection.py +++ b/examples/nfts/get_by_collection.py @@ -1,5 +1,5 @@ """Get NFT items from collection by collection address.""" -from pytonapi import Tonapi +from pytonapi import AsyncTonapi # Enter your API key API_KEY = "" # noqa @@ -8,9 +8,9 @@ ACCOUNT_ID = "EQAUxYSo-UwoqAGixaD3d7CNLp9PthgmEZfnr6BvsijzJHdA" # noqa -def main(): - tonapi = Tonapi(api_key=API_KEY) - result = tonapi.nft.get_items_by_collection_address(account_id=ACCOUNT_ID, limit=100) +async def main() -> None: + tonapi = AsyncTonapi(api_key=API_KEY) + result = await tonapi.nft.get_items_by_collection_address(account_id=ACCOUNT_ID, limit=100) for nft in result.nft_items: print(f"NFT address (raw): {nft.address.to_raw()}") @@ -27,4 +27,6 @@ def main(): if __name__ == '__main__': - main() + import asyncio + + asyncio.run(main()) diff --git a/examples/nfts/get_by_owner.py b/examples/nfts/get_by_owner.py index 2189105..5c2965c 100644 --- a/examples/nfts/get_by_owner.py +++ b/examples/nfts/get_by_owner.py @@ -1,5 +1,5 @@ """Get NFT items by owner address.""" -from pytonapi import Tonapi +from pytonapi import AsyncTonapi # Enter your API key API_KEY = "" # noqa @@ -8,9 +8,9 @@ ACCOUNT_ID = "EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess" # noqa -def main(): - tonapi = Tonapi(api_key=API_KEY) - result = tonapi.accounts.get_nfts(account_id=ACCOUNT_ID, limit=10) +async def main() -> None: + tonapi = AsyncTonapi(api_key=API_KEY) + result = await tonapi.accounts.get_nfts(account_id=ACCOUNT_ID, limit=10) for nft in result.nft_items: print(f"NFT address (raw): {nft.address.to_raw()}") @@ -28,4 +28,6 @@ def main(): if __name__ == '__main__': - main() + import asyncio + + asyncio.run(main())