Skip to content

Commit

Permalink
overview and installation (from DEN)
Browse files Browse the repository at this point in the history
  • Loading branch information
stechu committed Feb 6, 2020
1 parent cf50c65 commit f7f46e9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
Install PyTeal
==============

The easiest way of installing PyTeal is using :code:`pip` : ::

pip install pyteal

You can also install from source:

TODO: instructions for install from source


72 changes: 72 additions & 0 deletions docs/overview.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
Overview
========

With PyTeal, developers can easily write `Algorand Smart Contracts (ASC1s) <https://developer.algorand.org/docs/asc>`_ in Python.

Below is the example of writing *Hashed Time Locked Contract* in Pyteal::

from pyteal import *

""" Hash Time Locked Contract
"""
alice = Addr("6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY")
bob = Addr("7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M")
secret = Bytes("base32", "23232323232323")

fee_cond = Txn.fee() < Int(1000)
type_cond = Txn.type_enum() == Int(1)
recv_cond = And(Txn.close_remainder_to() == Global.zero_address(),
Txn.receiver() == alice,
Sha256(Arg(0)) == secret)
esc_cond = And(Txn.close_remainder_to() == Global.zero_address(),
Txn.receiver() == bob,
Txn.first_valid() > Int(3000))

atomic_swap = And(fee_cond,
type_cond,
Or(recv_cond, esc_cond))

print(atomic_swap.teal())


As shown in this exmaple, the logic of smart contract is expressed using PyTeal expressions constructed in Python. PyTeal overloads Python's arithmetic operators
such as :code:`<` and :code:`==` (more overloaded operators can be found in TODO), allowing Python developers express smart contract logic more naturally.

Last, :code:`teal()` is called to convert an PyTeal expression
to a TEAL program, consisting a sequence of TEAL opcodes.
The output of the above example is: ::

txn Fee
int 1000
<
txn TypeEnum
int 1
==
&&
txn CloseRemainderTo
global ZeroAddress
==
txn Receiver
addr 6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY
==
&&
arg 0
sha256
byte base32 23232323232323
==
&&
txn CloseRemainderTo
global ZeroAddress
==
txn Receiver
addr 7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M
==
&&
txn FirstValid
int 3000
>
&&
||
&&

0 comments on commit f7f46e9

Please sign in to comment.