Skip to content

Commit

Permalink
Update examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
nessshon committed Dec 19, 2024
1 parent 68f3ce7 commit 448aaa6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
12 changes: 7 additions & 5 deletions examples/accounts/get_all_address_formats.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -23,4 +23,6 @@ def main():


if __name__ == '__main__':
main()
import asyncio

asyncio.run(main())
12 changes: 7 additions & 5 deletions examples/accounts/get_info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Get account info."""
from pytonapi import Tonapi
from pytonapi import AsyncTonapi

# Enter your API key
API_KEY = "" # noqa
Expand All @@ -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
Expand All @@ -30,4 +30,6 @@ def main():


if __name__ == '__main__':
main()
import asyncio

asyncio.run(main())
12 changes: 7 additions & 5 deletions examples/accounts/get_transactions.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}")
Expand All @@ -26,4 +26,6 @@ def main():


if __name__ == '__main__':
main()
import asyncio

asyncio.run(main())
12 changes: 7 additions & 5 deletions examples/nfts/get_by_collection.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()}")
Expand All @@ -27,4 +27,6 @@ def main():


if __name__ == '__main__':
main()
import asyncio

asyncio.run(main())
12 changes: 7 additions & 5 deletions examples/nfts/get_by_owner.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()}")
Expand All @@ -28,4 +28,6 @@ def main():


if __name__ == '__main__':
main()
import asyncio

asyncio.run(main())

0 comments on commit 448aaa6

Please sign in to comment.