From 20f68ef94ed1ffa16273d1ab88b6379c58fa8d1a Mon Sep 17 00:00:00 2001 From: Camilo Molano Date: Fri, 3 May 2024 09:23:10 -0500 Subject: [PATCH 01/10] Update post-create.sh --- post-create.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/post-create.sh b/post-create.sh index f4bebbdf..4745425b 100644 --- a/post-create.sh +++ b/post-create.sh @@ -4,8 +4,7 @@ echo "running" pipx install poetry pip install typing-extensions poetry init -n -poetry add git+https://github.com/algorandfoundation/algokit-utils-py#feat/algorand_client -poetry env use python3.12 +poetry add git+https://github.com/algorandfoundation/algokit-utils-py poetry shell From caf3cf31d0ac86ce19eee4d6a0eff1f0f480062b Mon Sep 17 00:00:00 2001 From: Camilo Molano Date: Mon, 19 Aug 2024 08:02:27 -0500 Subject: [PATCH 02/10] Update and rename post-create.sh to algorand_setup.sh --- post-create.sh => algorand_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename post-create.sh => algorand_setup.sh (84%) diff --git a/post-create.sh b/algorand_setup.sh similarity index 84% rename from post-create.sh rename to algorand_setup.sh index 4745425b..07c2df8d 100644 --- a/post-create.sh +++ b/algorand_setup.sh @@ -1,6 +1,6 @@ #!/bin/bash -echo "running" +echo "Configurando el entorno" pipx install poetry pip install typing-extensions poetry init -n From f3c9a128ec5f6eddf9480e6c66cf7bb87940e0c1 Mon Sep 17 00:00:00 2001 From: Camilo Molano Date: Mon, 19 Aug 2024 08:31:15 -0500 Subject: [PATCH 03/10] Update algorand_setup.sh --- algorand_setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/algorand_setup.sh b/algorand_setup.sh index 07c2df8d..ecd8dac0 100644 --- a/algorand_setup.sh +++ b/algorand_setup.sh @@ -5,6 +5,7 @@ pipx install poetry pip install typing-extensions poetry init -n poetry add git+https://github.com/algorandfoundation/algokit-utils-py +poetry env use python3.12 poetry shell From d38fb320f0ee2b60c786de7c955b853015ec9434 Mon Sep 17 00:00:00 2001 From: Camilo Molano Date: Mon, 19 Aug 2024 08:38:44 -0500 Subject: [PATCH 04/10] Update algorand_setup.sh --- algorand_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorand_setup.sh b/algorand_setup.sh index ecd8dac0..b5d0e774 100644 --- a/algorand_setup.sh +++ b/algorand_setup.sh @@ -4,8 +4,8 @@ echo "Configurando el entorno" pipx install poetry pip install typing-extensions poetry init -n -poetry add git+https://github.com/algorandfoundation/algokit-utils-py poetry env use python3.12 +poetry add git+https://github.com/algorandfoundation/algokit-utils-py poetry shell From dad7f4e6894a6de4f3d295112b7f48568c987eac Mon Sep 17 00:00:00 2001 From: Camilo Molano Date: Mon, 19 Aug 2024 08:43:12 -0500 Subject: [PATCH 05/10] Update algorand_setup.sh --- algorand_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorand_setup.sh b/algorand_setup.sh index b5d0e774..73013134 100644 --- a/algorand_setup.sh +++ b/algorand_setup.sh @@ -2,9 +2,9 @@ echo "Configurando el entorno" pipx install poetry -pip install typing-extensions poetry init -n poetry env use python3.12 +pip install typing-extensions poetry add git+https://github.com/algorandfoundation/algokit-utils-py poetry shell From 5fd552e3478cbe07aa75a501b38dbd152f12cc6f Mon Sep 17 00:00:00 2001 From: Camilo Molano Date: Mon, 19 Aug 2024 08:54:58 -0500 Subject: [PATCH 06/10] Update algorand_setup.sh --- algorand_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorand_setup.sh b/algorand_setup.sh index 73013134..c5b25efb 100644 --- a/algorand_setup.sh +++ b/algorand_setup.sh @@ -3,8 +3,8 @@ echo "Configurando el entorno" pipx install poetry poetry init -n -poetry env use python3.12 pip install typing-extensions +poetry env use python3.12 poetry add git+https://github.com/algorandfoundation/algokit-utils-py poetry shell From fe8cf3f303b8670469414d7d7471ab76feb9c421 Mon Sep 17 00:00:00 2001 From: Camilo Molano Date: Mon, 19 Aug 2024 09:13:14 -0500 Subject: [PATCH 07/10] Update algorand_setup.sh --- algorand_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorand_setup.sh b/algorand_setup.sh index c5b25efb..73013134 100644 --- a/algorand_setup.sh +++ b/algorand_setup.sh @@ -3,8 +3,8 @@ echo "Configurando el entorno" pipx install poetry poetry init -n -pip install typing-extensions poetry env use python3.12 +pip install typing-extensions poetry add git+https://github.com/algorandfoundation/algokit-utils-py poetry shell From 7ebc77c1c6cae1640e2c6e6f409ec06b642b4f9b Mon Sep 17 00:00:00 2001 From: Camilo Molano Date: Mon, 19 Aug 2024 10:17:41 -0500 Subject: [PATCH 08/10] Update algorand_setup.sh --- algorand_setup.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/algorand_setup.sh b/algorand_setup.sh index 73013134..c65116f0 100644 --- a/algorand_setup.sh +++ b/algorand_setup.sh @@ -3,7 +3,6 @@ echo "Configurando el entorno" pipx install poetry poetry init -n -poetry env use python3.12 pip install typing-extensions poetry add git+https://github.com/algorandfoundation/algokit-utils-py poetry shell From 6cbf6eb63699b0252a71fb5eba27c54bc59b82b6 Mon Sep 17 00:00:00 2001 From: Camilo Molano Date: Tue, 20 Aug 2024 17:57:15 -0500 Subject: [PATCH 09/10] Update algorand_setup.sh --- algorand_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorand_setup.sh b/algorand_setup.sh index c65116f0..fbf6ad5f 100644 --- a/algorand_setup.sh +++ b/algorand_setup.sh @@ -1,9 +1,9 @@ #!/bin/bash echo "Configurando el entorno" +pip install typing-extensions pipx install poetry poetry init -n -pip install typing-extensions poetry add git+https://github.com/algorandfoundation/algokit-utils-py poetry shell From ff05d311642ec6b257be9accf96b2d699c4d2351 Mon Sep 17 00:00:00 2001 From: AbdulWasay14 <119948876+AbdulWasay14@users.noreply.github.com> Date: Sun, 25 Aug 2024 20:19:25 +0000 Subject: [PATCH 10/10] building with python on algorand, workshop challenge --- algokit-utils-py | 1 + main.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 14 ++++++++ 3 files changed, 107 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 00000000..816b548d --- /dev/null +++ b/algokit-utils-py @@ -0,0 +1 @@ +Subproject commit 816b548da68b76dcdd53788db3a47736d8646668 diff --git a/main.py b/main.py index 8b137891..c7a97352 100644 --- a/main.py +++ b/main.py @@ -1 +1,93 @@ +from algokit_utils.beta.algorand_client import ( + AlgorandClient, + AssetCreateParams, + AssetOptInParams, + AssetTransferParams, + PayParams +) +# Initialize the Algorand client for connecting to a local network +algorand=AlgorandClient.default_local_net() + +# Access the default dispenser account from KMD to use for funding other accounts +dispenser= algorand.account.dispenser() +print("Dispenser Account Address:", dispenser.address) + +# Create a new random account to act as the asset creator +creator_account =algorand.account.random() +print("Asset Creator Account Address:", creator_account.address) + +# Fund the asset creator account by sending ALGOs from the dispenser +algorand.send.payment( + PayParams( + sender=dispenser.address, + receiver=creator_account.address, + amount=10_000_000 # Send 10 ALGOs to the creator account + ) +) + +# Create a new Algorand Standard Asset (ASA) using the creator account +asset_creation_txn = algorand.send.asset_create( + AssetCreateParams( + sender=creator_account.address, + total=100, # Set total supply of the asset to 100 units + asset_name="KnowledgeCoin", # Name of the asset + unit_name="KNL" # Ticker + ) +) + +# Retrieve the Asset ID from the confirmed transaction response +asset_id = asset_creation_txn["confirmation"]["asset-index"] +print("Created Asset ID:", asset_id) + +# Generate another random account to receive the asset +receiver_account = algorand.account.random() + +# Fund the receiver account with 10 ALGOs from the dispenser +algorand.send.payment( + PayParams( + sender=dispenser.address, + receiver=receiver_account.address, + amount=10_000_000 # Send 10 ALGOs to the receiver account + ) +) + +# Create a group transaction for multiple actions that will be executed atomically +group_txn = algorand.new_group() + +# Opt the receiver account into the newly created asset (enabling it to receive the asset) +group_txn.add_asset_opt_in( + AssetOptInParams( + sender=receiver_account.address, + asset_id=asset_id + ) +) + +# Add a transaction to send 1 ALGO from the receiver to the creator +group_txn.add_payment( + PayParams( + sender=receiver_account.address, + receiver=creator_account.address, + amount=1_000_000 # Send 1 ALGO from the receiver to the creator + ) +) + +# Transfer 10 units of the newly created asset from the creator to the receiver +group_txn.add_asset_transfer( + AssetTransferParams( + sender=creator_account.address, + receiver=receiver_account.address, + asset_id=asset_id, + amount=10 # Transfer 10 units of the asset to the receiver + ) +) + +# Execute the group transaction, ensuring all transactions happen together or not at all +group_txn.execute() + +# Retrieve and print the updated asset balance for both the receiver and the creator +receiver_asset_balance = algorand.account.get_information(receiver_account.address)["assets"][0]["amount"] +creator_asset_balance = algorand.account.get_information(creator_account.address)["assets"][0]["amount"] + +print("Receiver's Asset Balance:", receiver_asset_balance) +print("Creator's Asset Balance:", creator_asset_balance) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..aaf08cca --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[tool.poetry] +name = "codespace-algorand" +version = "0.1.0" +description = "" +authors = ["AbdulWasay14 <119948876+AbdulWasay14@users.noreply.github.com>"] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.12" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"