From a35693377608994f71f8b84a8d9d0bb0c895d4f4 Mon Sep 17 00:00:00 2001 From: Paul Attah <87580611+paulattah@users.noreply.github.com> Date: Thu, 29 Aug 2024 12:35:33 +0000 Subject: [PATCH] paul attah --- algokit-utils-py | 1 + main.py | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 14 ++++++++ 3 files changed, 100 insertions(+) create mode 160000 algokit-utils-py create mode 100644 pyproject.toml diff --git a/algokit-utils-py b/algokit-utils-py new file mode 160000 index 0000000..816b548 --- /dev/null +++ b/algokit-utils-py @@ -0,0 +1 @@ +Subproject commit 816b548da68b76dcdd53788db3a47736d8646668 diff --git a/main.py b/main.py index 8b13789..8b9d0e0 100644 --- a/main.py +++ b/main.py @@ -1 +1,86 @@ +from algokit_utils.beta.algorand_client import ( + AlgorandClient, + AssetCreateParams, + AssetOptInParams, + AssetTransferParams, + PayParams, +) +# Client to connect to localnet +algorand = AlgorandClient.default_local_net() + +# Import dispenser from KMD +dispenser = algorand.account.dispenser() +#print("Dispenser Address:", dispenser.address) + +creator = algorand.account.random() +#print("Creator Address:", creator.address) +#print(algorand.account.get_information(creator.address)) + +# Fund creator account +algorand.send.payment( + PayParams( + sender=dispenser.address, + receiver=creator.address, + amount=10_000_000 # 10 algos + ) +) + +#print(algorand.account.get_information(creator.address)) + +sent_txn = algorand.send.asset_create( + AssetCreateParams( + sender=creator.address, + total=100, + asset_name="Edu4Teen", + unit_name="E4T", + ) +) + +asset_id=sent_txn["confirmation"]["asset-index"] +print("Asset ID", asset_id) + +receiver_acct = algorand.account.random() + +# Fund receiver_acct account +algorand.send.payment( + PayParams( + sender=dispenser.address, + receiver=receiver_acct.address, + amount=10_000_000 # 10 algos + ) +) + +print(algorand.account.get_information(receiver_acct.address)) + +# create a group txn +group_txn = algorand.new_group() + +group_txn.add_asset_opt_in( + AssetOptInParams( + sender=receiver_acct.address, + asset_id=asset_id + ) +) + +group_txn.add_payment( + PayParams( + sender=receiver_acct.address, + receiver=creator.address, + amount=1_000_000 # 1 algo + ) +) + +group_txn.add_asset_transfer( + AssetTransferParams( + sender=creator.address, + receiver=receiver_acct.address, + asset_id=asset_id, + amount=10 + ) +) + +group_txn.execute() + +print("Receiver Account Asset Balance:", algorand.account.get_information(receiver_acct.address)['assets'][0]['amount']) +print("Creator Account Asset Balance:", algorand.account.get_information(creator.address)['assets'][0]['amount']) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..81108b6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[tool.poetry] +name = "codespace-algorand" +version = "0.1.0" +description = "" +authors = ["Paul Attah <87580611+paulattah@users.noreply.github.com>"] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.12" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"