Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved - Building with Python on Blockchain With Algorand #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1 +1,88 @@
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"
)
)
# print(sent_txn)

asset_id = sent_txn["confirmation"]["asset-index"]
print("Asset ID:", asset_id)

receiver_acct = algorand.account.random()
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(
# asset_transfer = algorand.send.asset_transfer( # We don't need this because we are adding this txn to a txn group...
AssetTransferParams(
sender=creator.address,
receiver=receiver_acct.address,
asset_id=asset_id,
amount=10
)
# )
)

group_txn.execute()

print("\nFor Algorand, with Love, from Pasquale Silvestre:")
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"])
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.poetry]
name = "codespace-algorand"
version = "0.1.0"
description = ""
authors = ["Pasquale-Silv <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"