Educational project demonstrating Algorand blockchain development using Python and AlgoKit Utils. This repository provides practical examples of account management, transactions, and asset operations on the Algorand blockchain.
- β Create/load accounts from environment variables
- β Generate random testnet accounts
- β Check account balances
- β Convert between mnemonic and private keys
- β Support for LocalNet, TestNet, and MainNet
- β Automatic account funding on LocalNet
- β Simple payment transactions (ALGO transfers)
- β Atomic group transactions (all-or-nothing execution)
- β
Flexible input (accepts
SigningAccountor address strings) - β Automatic microAlgo conversion
- β Create custom assets (tokens/NFTs)
- β Opt-in to assets (enable receiving)
- β Opt-out from assets (remove from account)
- β Transfer assets between accounts
- β Check asset balances
- β Support for decimals and asset configuration
- Python 3.14+
- Poetry (dependency management)
- Docker (for LocalNet)
- AlgoKit CLI
-
Clone the repository:
git clone https://github.com/CorvidLabs/algo-utils-examples.git cd algo-utils-examples -
Install dependencies:
poetry install
-
Start Algorand LocalNet:
algokit localnet start
β³ Wait 30-60 seconds for LocalNet to fully initialize.
-
(Optional) Configure custom accounts:
Create a
.envfile in the project root:JOAO_MNEMONIC="your 25 word mnemonic phrase here" JOSE_MNEMONIC="your 25 word mnemonic phrase here"
Note: If you don't create a
.envfile, LocalNet will automatically generate and manage accounts using KMD. -
Run the examples:
poetry run python -m algo_utils_examples.main
Or if you've configured the script in
pyproject.toml:poetry run algo-utils-examples
from algo_utils_examples.accounts import create_account, get_balance
from algokit_utils import AlgorandClient
# Create Algorand client
algorand = AlgorandClient.default_localnet()
# Load account from environment (or create via KMD if not found)
account = create_account(algorand, "SARA", initial_algo=1000)
# Check balance
balance = get_balance(algorand, account.address)
print(f"Balance: {balance} ALGO")from algo_utils_examples.transaction import payment
# Send 10 ALGO from Sara to Jose
result = payment(
algorand=algorand,
sender=sara, # Can be SigningAccount or address string
receiver=jose,
algo=10.0,
note=b"Payment for services"
)
print(f"Transaction ID: {result.tx_id}")from algo_utils_examples.transaction import group_transaction
from algokit_utils import PaymentParams, AlgoAmount
# Multiple payments that execute together (atomic)
params = [
PaymentParams(
sender=sara.address,
receiver=jose.address,
amount=AlgoAmount.from_algo(5),
note=b"Payment 1"
),
PaymentParams(
sender=jose.address,
receiver=sara.address,
amount=AlgoAmount.from_algo(3),
note=b"Payment 2"
)
]
result = group_transaction(algorand, params)
print(f"Group ID: {result.group_id}")from algo_utils_examples.assets import create_asset
# Create a token with 6 decimals
asset_id = create_asset(
algorand=algorand,
sender=sara,
name="My Token",
unit_name="MTK",
total=1_000_000_000_000, # 1 trillion base units
decimals=6, # = 1 million whole tokens
frozen=False
)
print(f"Asset ID: {asset_id}")from algo_utils_examples.assets import opt_in, assets_transfer, get_asset_balance
# Jose opts in to receive the asset
opt_in(algorand, jose, asset_id)
# Sara transfers 100 tokens to Jose (considering decimals=6)
# To transfer 100 whole tokens: 100 Γ 10^6 = 100,000,000 base units
assets_transfer(
algorand=algorand,
sender=sara,
receiver=jose,
asset_id=asset_id,
amount=100_000_000, # 100 tokens with 6 decimals
note=b"Token transfer"
)
# Check Jose's balance
balance = get_asset_balance(algorand, jose, asset_id)
print(f"Jose's token balance: {balance}")algo-utils-examples/
βββ src/
β βββ algo_utils_examples/
β βββ __init__.py
β βββ accounts.py # Account management utilities
β βββ transaction.py # Payment and group transactions
β βββ assets.py # Asset creation and operations
β βββ main.py # Example usage and demonstrations
βββ tests/ # Unit tests (to be added)
βββ .env # Environment variables (optional, not in git)
βββ pyproject.toml # Project dependencies and configuration
βββ poetry.lock # Locked dependencies
βββ README.md # This file
Assets on Algorand use base units (integers) internally, but can display decimal places to users:
decimals=0: Whole units only (e.g., NFTs)decimals=2: Like dollars and cents (1.00)decimals=6: Like USDC (1.000000)
Example: An asset with total=1_000_000 and decimals=2 displays as 10,000.00 to users.
Formula:
Value shown to user = total Γ· (10^decimals)
Atomic group transactions ensure all transactions succeed or all fail together. This is perfect for:
- Swaps/trades
- Multi-party agreements
- Complex operations that must be atomic
Before receiving an asset, accounts must opt-in to it. This:
- Prevents spam assets
- Gives users control over their account
- Requires a small ALGO balance to maintain
| Technology | Purpose |
|---|---|
| Python 3.14 | Programming language |
| AlgoKit Utils | Algorand SDK wrapper |
| Poetry | Dependency management |
| Algorand LocalNet | Local blockchain for testing |
| Docker | Containerization for LocalNet |
| algosdk | Algorand Python SDK |
# Stop and reset LocalNet
algokit localnet reset
# Start fresh
algokit localnet start- Make sure
.envfile has correct mnemonic phrases - Or let LocalNet auto-generate accounts (don't use
.env)
- Check account balance:
get_balance(algorand, address) - Fund TestNet accounts using the TestNet Dispenser
- Before receiving assets, run:
opt_in(algorand, account, asset_id)
- Make sure you're running as a module:
poetry run python -m algo_utils_examples.main - Or configure script in
pyproject.tomland use:poetry run algo-utils-examples
This is an educational project, but contributions are welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project was developed as a learning exercise with assistance from:
- AI Tools: Claude/Cursor for code review, best practices, and blockchain concepts
- Mentors: Leif and Gaspar for programming guidance and support
- Algorand Foundation: For excellent documentation and tools
MIT License - see LICENSE file for details
Happy coding on Algorand! π