Create Publication

We are looking for publications that demonstrate building dApps or smart contracts!
See the full list of Gitcoin bounties that are eligible for rewards.

Article Thumbnail

Updated PyTeal Resources

PyTeal is a Python language binding for constructing Algorand Smart Contracts. It was created as a community project to make writing contracts even easier and more accessible to developers who prefer programming in Python.

In case you missed it, be sure to check out this article, by the creator of PyTeal, for an overview of the language, a walkthrough example, and some other tips and resources available for getting started writing Smart Contracts on Algorand with Python.

In this article, we will summarize the latest PyTeal resources available for devs, including some new PyTeal Tutorials covering periodic payments, hash time lock contracts, and dynamic fees.

PyTeal Documentation

First, read the docs. It includes an overview of the language and how it maps to underlying TEAL. PyTeal supports certain cryptographic primitives, data type conversions, accessing transaction and grouped transaction properties, globals, and the addition of conditional logic.

Tutorials

A great way to get started with PyTeal is to work against known TEAL templates and try and produce the same TEAL code through PyTeal. You can find a set of TEAL templates in the reference docs starting here with delegate key registration.

Tutorial: Dynamic Fee Template with PyTeal

The Dynamic Fee Tutorial shows how to construct a contract that allows an account to pay the transaction fee on behalf of another sender. In this tutorial, Bob can pay the transaction fee for a transaction that is sent from Alice to Charlie.

In this tutorial, you will learn how TEAL can be used to check transaction properties within an atomic transfer that is composed of: 1) the transaction from Bob to Alice to cover the fee and 2) the main transaction from Alice to Charlie.

You will also learn how to build the atomic transfer and authorize its components with Bob’s private key (for the first transaction) and a Logic Signature (for the second) through TEAL’s delegated approval mechanism.

Tutorial: Hash Time Lock Contract with PyTeal

The Hash Time Lock Contract Tutorial walks through the creation of an escrow account that releases funds to either someone who supplies a passcode, hashed with a specific cryptographic function, or to the original escrow creator after the contract expires.

As you learn how to construct the aforementioned scenario, you will also see examples of how to use TEAL’s hash function opcodes and how to pass parameters to a TEAL program.

Tutorial: Periodic Payment using PyTeal

The Periodic Payment Tutorial illustrates setting up a periodic payment from one account to another. For example, let’s say Bob needs to pay back a loan to Charlie. Bob delegates his signature to allow Charlie to withdraw X amount from Bob’s account every Y rounds.

As part of this tutorial, you will learn how to create a Logic Signature that is used to delegate an account’s signature for transactions governed by the TEAL program. You will also learn how to limit transactions to a specific period of rounds and how to effectively expire a logic signature. This example is based on the Periodic Payment Template but uses delegated approval instead of a contract account.

Conclusion

We hope you find these resources useful and we are excited to see what other use cases you can solve using PyTeal! Remember that if you have interesting use cases to share in the form of Tutorials or Solutions, please submit them for the opportunity to be published.

Check back often for more content and don’t forget to subscribe to the developer newsletter to get the latest resources and updates for PyTeal and more.