A basic starter template to learn PyTeal development for Algorand blockchain smart-contracts.
- Install Git
- Install Docker Desktop
- Install Algorand sandbox
- Copy this project without cloning:
git clone -b main --depth 1 --single-branch git@github.com:manustays/algorand-pyteal-smart-contract-starter-template.git && rm -rf algorand-pyteal-smart-contract-starter-template/.git/
- Start Docker Desktop and goto the Sandbox folder
- Add your project folder as bind volume in the Sandbox Docker image:
- In the Sandbox root folder, edit the file
docker-compose.yml
and add the following lines under the keyservices.algod
:volumes: - type: bind source: <path to this project folder> target: /data
- In the Sandbox root folder, edit the file
- Start the Sandbox docker container with the command:
./sandbox up -v
- Other useful Sandbox commands (after starting it):
- Shut down the Sandbox:
./sandbox down
- Get a list of test wallets/accounts:
./sandbox goal account list
- Check the balance of an account (app account or wallet):
./sandbox goal balance --address <account-address>
- Reset Sandbox (including the test accounts):
./sandbox reset
- Shut down the Sandbox:
- Goto project folder & setup Python virtual env for the project (one time only):
python3 -m venv venv
- Activate the Python virtual environment (everytime you start this project):
$ ./venv/Scripts/activate # Windows $ ./venv/bin/activate # Linux/Mac
- Check if virtual env is setup properly:
pip -V
- It should show the path to Python executable under your project's venv folder.
- Install the python dependencies (one time only):
pip3 install -r requirements.txt
- Within the project folder:
- Activate the Python virtual environment (if not already done):
. venv/bin/activate
- Build source files:
./build.sh contracts.<subfolder>.<filename-without-py-ext>
- Activate the Python virtual environment (if not already done):
- Within the Sandbox folder:
-
Enter the docker container terminal:
./sandbox enter algod
-
Check if project’s bound volume is working:
ls /data
-
Get test wallet accounts:
goal account list
- Copy account address in a variable for easy access:
WALLET1=F74DX......
- Copy account address in a variable for easy access:
-
Deploy contract within sandbox:
goal app create --creator $WALLET1 --approval-prog /data/build/approval.teal --clear-prog /data/build/clear.teal --global-byteslices 1 --global-ints 3 --local-byteslices 0 --local-ints 0
- It returns a numeric app ID if successfully deployed (eg: 1)
- Store in a variable for easy access:
APPID=1
-
Get deployed app info:
goal app info --app-id $APPID
-
Read smart contract storage:
goal app read --global --app-id $APPID --guess-format
-
Maintain minimum balance (0.1 algo or 100,000 microalgo) in the smart contract account:
goal clerk send -f $WALLET1 -t $APP_ACCOUNT -a 100000
-
Call a Smart Contract Operation:
goal app call --app-id $APPID --from $WALLET1 --app-arg "str:inc"
-
Sandbox comes with the tealdbg
tool for debugging. It requires a transaction dump file as input that we can generate while executing the smart-contract.
- Generate the transaction dump file:
goal app call --app-id $APPID --from $WALLET1 --app-arg "str:dec" **--dryrun-dump -o tx.dr**
- Start debugger session:
tealdbg debug -d tx.dr --listen 0.0.0.0
- The debug port (9392) can also be found from the
docker-compose.yml
file under the key:CDT_PORT
.
- The debug port (9392) can also be found from the
- Open the Chrome browser and goto
chrome://inspect/#devices
- Official Algorand Smart Contract Guidelines
- PyTeal Documentation
- Algorand DevRel Example Contracts
- Awesome-Algorand
- Forked from algorand-devrel/pyteal-course.
- Accompanying tutorial on YouTube