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

algo challenge by ansar #5

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
116 changes: 115 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,115 @@
# codespace_algorand
# The All-in-One Algorand Codespace

Welcome to the all-in-one Algorand Codespace! This repository is designed to provide you with everything you need to start developing on the Algorand blockchain, whether you're attending a workshop, completing a challenge, or just exploring on your own.

## 🌟 Quick Start Guide

### **Fork the Repo:**

To create your own copy of this repository:

a. **Go to the GitHub Repository:**
- Navigate to the main page which is the current one your on.

b. **Click the "Fork" Button:**
- In the top-right corner of the page, click the **Fork** button. This will create a copy of the repository under your GitHub account.

c. **Wait for the Forking Process to Complete:**
- GitHub will take a few moments to create the fork. Once complete, you’ll be redirected to your newly created fork.

## 🚀 Start with Codespaces
This is the fastest way to get up and running!

1. **Create a Codespace:**


https://github.com/user-attachments/assets/1513fd15-b55a-48e5-8b97-ba128a74fe43


*Click the image above to watch a quick 15-second video on how to create your Codespace.*
- Click the green "Code" button at the top right of your forked repo.
- Select "Create codespace on main".
- Once your Codespace is fully loaded, run the following command in the terminal:
```bash
sh algorand_setup.sh
```

2. **Start Coding:**
- Open the `main.py` file to start coding and interact with the Algorand blockchain (no smart contracts needed).
- To start a smart contract/dApp project, run:
```bash
algokit init
```

3. **Workshop Follow-Along:**
- If you're participating in a workshop, the code we’ll be using is available [here](https://github.com/Ganainmtech/python_algokit_demo).

4. **Explore on Your Own:**
- Use this environment to write your own scripts or modify existing ones.

## 💻 Advanced Setup for Local Development

Prefer a local environment? Follow these steps:

#### 🧰 Prerequisites

- Install Python 3.12 or higher.
- Install [AlgoKit](https://developer.algorand.org/algokit/?utm_source=af_employee&utm_medium=social&utm_campaign=algokit_sarajane&utm_content=download&utm_term=EME).
- Install Docker (for running a local Algorand network).

#### 🔧 Setup Instructions

1. **Fork & Clone the Repository:**


https://github.com/user-attachments/assets/6942cc23-72c1-4d89-a4aa-f2f4fe8fcfe0


*Watch this video to see how to fork and clone a repository.*
- Fork this repository to your GitHub account.
- Clone the repository to your local machine:
```bash
cd [DIRECTORY_OF_YOUR_CHOICE]
git clone [FORKED_REPO_URL]
```

2. **Open in VSCode:**
- Open the repository with your code editor.

3. **Bootstrap Your Project:**
- Navigate to the [`main.py`](./main.py) file.
- Run the following command to set up your environment for simple scripts:
```bash
sh algorand_setup.sh
```
- If you are looking into smart contracts and algokit run the following commands:
```bash
algokit init
algokit project bootstrap
```
- This installs dependencies and generates a `.env` file if you are using algokit.

## 🎓 Workshop Challenges

If you’re taking part in a workshop challenge you can choose to fork and enter codespace or fork and work locally:

1. **Live coding follow along:**
- Complete the task provided during the workshop.

2. **Submit Your Answer:**
- Push your changes to your forked GitHub repository.
- Create a Pull Request (PR) to the original repository.
- In your PR, include:
- What your script achieves. (Optional)

## 📚 Additional Resources

- **Level Up:** Move to a local development environment when you're ready! Check out the [AlgoKit Landing Page](https://developer.algorand.org/algokit/?utm_source=af_employee&utm_medium=social&utm_campaign=algokit_sarajane&utm_content=download&utm_term=EME) for a quick setup guide.
- **Join the Community:**
- [![Join Algorand Discord](https://img.shields.io/discord/discord_channel_id?logo=discord)](https://discord.com/invite/algorand)
- [![Follow Algodevs on Twitter](https://img.shields.io/twitter/follow/algodevs?style=social)](https://x.com/algodevs)

## 🏁 Conclusion

This repository serves as both a playground for exploration and a platform for structured learning through workshops and challenges. Whether you're a beginner or an experienced developer, we hope you find this environment useful and engaging. Happy coding!

1 change: 1 addition & 0 deletions algokit-utils-py
Submodule algokit-utils-py added at 816b54
17 changes: 17 additions & 0 deletions algorand_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

echo "Running setup script..."

pipx install poetry
pip install typing-extensions
poetry init -n
git clone https://github.com/algorandfoundation/algokit-utils-py.git
cd algokit-utils-py
pip install .
cd ..

echo "Setup completed."




86 changes: 86 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1 +1,87 @@
from algokit_utils.beta.algorand_client import(
AlgorandClient,
AssetCreateParams,
AssetOptInParams,
AssetTransferParams,
PayParams,
)

# client to connect to the local net
algorand = AlgorandClient.default_local_net()

dispenser = algorand.account.dispenser()
#print("Dispenser Address: ",dispenser.address)

# Generate creator wallet
creator = algorand.account.random()
#print("Creator Address: ",creator.address)
#print(algorand.account.get_information(creator.address))

# Fund creator address with algo
algorand.send.payment(
PayParams(
sender=dispenser.address,
receiver=creator.address,
amount=10_000_000 # 10 algos
)
)

#print(algorand.account.get_information(creator.address))

send_txn = algorand.send.asset_create(
AssetCreateParams(
sender=creator.address,
total=100,
asset_name="Edu4teen",
unit_name="E4T"
)
)

asset_id = send_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 new 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(algorand.account.get_information(receiver_acct.address))

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'])
13 changes: 0 additions & 13 deletions post-create.sh

This file was deleted.

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-algo-first"
version = "0.1.0"
description = ""
authors = ["Ansar Afsar <[email protected]>"]
readme = "README.md"

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


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