PyTeal Package

pyteal.Txn = <pyteal.TxnObject object>

The current transaction being evaluated.

pyteal.Gtxn = <pyteal.TxnGroup object>

The current group of transactions being evaluated.

class pyteal.Expr

Bases: abc.ABC

Abstract base class for PyTeal expressions.

And(other: pyteal.Expr) → pyteal.Expr

Take the logical And of this expression and another one.

This expression must evaluate to uint64.

This is the same as using And() with two arguments.

Or(other: pyteal.Expr) → pyteal.Expr

Take the logical Or of this expression and another one.

This expression must evaluate to uint64.

This is the same as using Or() with two arguments.

type_of() → pyteal.TealType

Get the return type of this expression.

class pyteal.LeafExpr

Bases: pyteal.Expr

Leaf expression base class.

class pyteal.Addr(address: str)

Bases: pyteal.LeafExpr

An expression that represents an Algorand address.

__init__(address: str) → None

Create a new Addr expression.

Parameters:address – A string containing a valid base32 Algorand address
type_of()

Get the return type of this expression.

class pyteal.Bytes(*args)

Bases: pyteal.LeafExpr

An expression that represents a byte string.

__init__(*args) → None

Create a new byte string.

Depending on the encoding, there are different arguments to pass:

For UTF-8 strings:
Pass the string as the only argument. For example, Bytes("content").
For base16, base32, or base64 strings:
Pass the base as the first argument and the string as the second argument. For example, Bytes("base16", "636F6E74656E74"), Bytes("base32", "ORFDPQ6ARJK"), Bytes("base64", "Y29udGVudA==").
Special case for base16:
The prefix “0x” may be present in a base16 byte string. For example, Bytes("base16", "0x636F6E74656E74").
type_of()

Get the return type of this expression.

class pyteal.Err

Bases: pyteal.LeafExpr

Expression that causes the program to immediately fail when executed.

type_of()

Get the return type of this expression.

class pyteal.Int(value: int)

Bases: pyteal.LeafExpr

An expression that represents a uint64.

__init__(value: int) → None

Create a new uint64.

Parameters:value – The integer value this uint64 will represent. Must be a positive value less than 2**64.
type_of()

Get the return type of this expression.

class pyteal.EnumInt(name: str)

Bases: pyteal.LeafExpr

An expression that represents uint64 enum values.

__init__(name: str) → None

Create an expression to reference a uint64 enum value.

Parameters:name – The name of the enum value.
type_of()

Get the return type of this expression.

class pyteal.Arg(index: int)

Bases: pyteal.LeafExpr

An expression to get an argument when running in signature verification mode.

__init__(index: int) → None

Get an argument for this program.

Should only be used in signature verification mode. For application mode arguments, see TxnObject.application_args.

Parameters:index – The integer index of the argument to get. Must be between 0 and 255 inclusive.
type_of()

Get the return type of this expression.

class pyteal.TxnType

Bases: object

Enum of all possible transaction types.

ApplicationCall = <pyteal.EnumInt object>
AssetConfig = <pyteal.EnumInt object>
AssetFreeze = <pyteal.EnumInt object>
AssetTransfer = <pyteal.EnumInt object>
KeyRegistration = <pyteal.EnumInt object>
Payment = <pyteal.EnumInt object>
Unknown = <pyteal.EnumInt object>
class pyteal.TxnField(id: int, name: str, type: pyteal.TealType)

Bases: enum.Enum

An enumeration.

accounts = (28, 'Accounts', <TealType.bytes: 1>)
amount = (8, 'Amount', <TealType.uint64: 0>)
application_args = (26, 'ApplicationArgs', <TealType.bytes: 1>)
application_id = (24, 'ApplicationID', <TealType.uint64: 0>)
approval_program = (30, 'ApprovalProgram', <TealType.bytes: 1>)
asset_amount = (18, 'AssetAmount', <TealType.uint64: 0>)
asset_close_to = (21, 'AssetCloseTo', <TealType.bytes: 1>)
asset_receiver = (20, 'AssetReceiver', <TealType.bytes: 1>)
asset_sender = (19, 'AssetSender', <TealType.bytes: 1>)
clear_state_program = (31, 'ClearStateProgram', <TealType.bytes: 1>)
close_remainder_to = (9, 'CloseRemainderTo', <TealType.bytes: 1>)
config_asset = (33, 'ConfigAsset', <TealType.uint64: 0>)
config_asset_clawback = (44, 'ConfigAssetClawback', <TealType.bytes: 1>)
config_asset_decimals = (35, 'ConfigAssetDecimals', <TealType.uint64: 0>)
config_asset_default_frozen = (36, 'ConfigAssetDefaultFrozen', <TealType.uint64: 0>)
config_asset_freeze = (43, 'ConfigAssetFreeze', <TealType.bytes: 1>)
config_asset_manager = (41, 'ConfigAssetManager', <TealType.bytes: 1>)
config_asset_metadata_hash = (40, 'ConfigAssetMetadataHash', <TealType.bytes: 1>)
config_asset_name = (38, 'ConfigAssetName', <TealType.bytes: 1>)
config_asset_reserve = (42, 'ConfigAssetReserve', <TealType.bytes: 1>)
config_asset_total = (34, 'ConfigAssetTotal', <TealType.uint64: 0>)
config_asset_unit_name = (37, 'ConfigAssetUnitName', <TealType.bytes: 1>)
config_asset_url = (39, 'ConfigAssetURL', <TealType.bytes: 1>)
fee = (1, 'Fee', <TealType.uint64: 0>)
first_valid = (2, 'FirstValid', <TealType.uint64: 0>)
first_valid_time = (3, 'FirstValidTime', <TealType.uint64: 0>)
freeze_asset = (45, 'FreezeAsset', <TealType.uint64: 0>)
freeze_asset_account = (46, 'FreezeAssetAccount', <TealType.bytes: 1>)
freeze_asset_frozen = (47, 'FreezeAssetFrozen', <TealType.uint64: 0>)
group_index = (22, 'GroupIndex', <TealType.uint64: 0>)
last_valid = (4, 'LastValid', <TealType.uint64: 0>)
lease = (6, 'Lease', <TealType.bytes: 1>)
note = (5, 'Note', <TealType.bytes: 1>)
num_accounts = (2, 'NumAccounts', <TealType.uint64: 0>)
num_app_args = (27, 'NumAppArgs', <TealType.uint64: 0>)
on_completion = (25, 'OnCompletion', <TealType.uint64: 0>)
receiver = (7, 'Receiver', <TealType.bytes: 1>)
rekey_to = (32, 'RekeyTo', <TealType.bytes: 1>)
selection_pk = (11, 'SelectionPK', <TealType.bytes: 1>)
sender = (0, 'Sender', <TealType.bytes: 1>)
tx_id = (23, 'TxID', <TealType.bytes: 1>)
type = (15, 'Type', <TealType.bytes: 1>)
type_enum = (16, 'TypeEnum', <TealType.uint64: 0>)
type_of() → pyteal.TealType
vote_first = (12, 'VoteFirst', <TealType.uint64: 0>)
vote_key_dilution = (14, 'VoteKeyDilution', <TealType.uint64: 0>)
vote_last = (13, 'VoteLast', <TealType.uint64: 0>)
vote_pk = (10, 'VotePK', <TealType.bytes: 1>)
xfer_asset = (17, 'XferAsset', <TealType.uint64: 0>)
class pyteal.TxnExpr(field: pyteal.TxnField)

Bases: pyteal.LeafExpr

An expression that accesses a transaction field from the current transaction.

type_of()

Get the return type of this expression.

class pyteal.TxnaExpr(field: pyteal.TxnField, index: int)

Bases: pyteal.LeafExpr

An expression that accesses a transaction array field from the current transaction.

type_of()

Get the return type of this expression.

class pyteal.TxnArray(txnObject: pyteal.TxnObject, accessField: pyteal.TxnField, lengthField: pyteal.TxnField)

Bases: pyteal.Array

Represents a transaction array field.

__getitem__(index: int) → pyteal.TxnaExpr

Get the value at a given index in this array.

length() → pyteal.TxnExpr

Get the length of the array.

class pyteal.TxnObject(txnType: Callable[[pyteal.TxnField], pyteal.TxnExpr], txnaType: Callable[[pyteal.TxnField, int], pyteal.TxnaExpr])

Bases: object

Represents a transaction and its fields.

accounts

Application call accounts array.

Type:TxnArray
amount() → pyteal.TxnExpr

Get the amount of the transaction in micro Algos.

Only set when type_enum() is TxnType.Payment.

For more information, see https://developer.algorand.org/docs/reference/transactions/#amount

application_args

Application call arguments array.

Type:TxnArray
application_id() → pyteal.TxnExpr

Get the application ID from the ApplicationCall portion of the current transaction.

Only set when type_enum() is TxnType.ApplicationCall.

approval_program() → pyteal.TxnExpr

Get the approval program.

Only set when type_enum() is TxnType.ApplicationCall.

asset_amount() → pyteal.TxnExpr

Get the amount of the asset being transferred, measured in the asset’s units.

Only set when type_enum() is TxnType.AssetTransfer.

For more information, see https://developer.algorand.org/docs/reference/transactions/#assetamount

asset_close_to() → pyteal.TxnExpr

Get the closeout address of the asset transfer.

Only set when type_enum() is TxnType.AssetTransfer.

For more information, see https://developer.algorand.org/docs/reference/transactions/#assetcloseto

asset_receiver() → pyteal.TxnExpr

Get the recipient of the asset transfer.

Only set when type_enum() is TxnType.AssetTransfer.

For more information, see https://developer.algorand.org/docs/reference/transactions/#assetreceiver

asset_sender() → pyteal.TxnExpr

Get the 32 byte address of the subject of clawback.

Only set when type_enum() is TxnType.AssetTransfer.

For more information, see https://developer.algorand.org/docs/reference/transactions/#assetsender

clear_state_program() → pyteal.TxnExpr

Get the clear state program.

Only set when type_enum() is TxnType.ApplicationCall.

close_remainder_to() → pyteal.TxnExpr

Get the 32 byte address of the CloseRemainderTo field.

Only set when type_enum() is TxnType.Payment.

For more information, see https://developer.algorand.org/docs/reference/transactions/#closeremainderto

config_asset() → pyteal.TxnExpr

Get the asset ID in asset config transaction.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#configasset

config_asset_clawback() → pyteal.TxnExpr

Get the 32 byte asset clawback address.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#clawbackaddr

config_asset_decimals() → pyteal.TxnExpr

Get the number of digits to display after the decimal place when displaying the asset.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#decimals

config_asset_default_frozen() → pyteal.TxnExpr

Check if the asset’s slots are frozen by default or not.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#defaultfrozen

config_asset_freeze() → pyteal.TxnExpr

Get the 32 byte asset freeze address.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#freezeaddr

config_asset_manager() → pyteal.TxnExpr

Get the 32 byte asset manager address.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#manageraddr

config_asset_metadata_hash() → pyteal.TxnExpr

Get the 32 byte commitment to some unspecified asset metdata.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#metadatahash

config_asset_name() → pyteal.TxnExpr

Get the asset name.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#assetname

config_asset_reserve() → pyteal.TxnExpr

Get the 32 byte asset reserve address.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#reserveaddr

config_asset_total() → pyteal.TxnExpr

Get the total number of units of this asset created.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#total

config_asset_unit_name() → pyteal.TxnExpr

Get the unit name of the asset.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#unitname

config_asset_url() → pyteal.TxnExpr

Get the asset URL.

Only set when type_enum() is TxnType.AssetConfig.

For more information, see https://developer.algorand.org/docs/reference/transactions/#url

fee() → pyteal.TxnExpr

Get the transaction fee in micro Algos.

For more information, see https://developer.algorand.org/docs/reference/transactions/#fee

first_valid() → pyteal.TxnExpr

Get the first valid round number.

For more information, see https://developer.algorand.org/docs/reference/transactions/#firstvalid

freeze_asset() → pyteal.TxnExpr

Get the asset ID being frozen or un-frozen.

Only set when type_enum() is TxnType.AssetFreeze.

For more information, see https://developer.algorand.org/docs/reference/transactions/#freezeasset

freeze_asset_account() → pyteal.TxnExpr

Get the 32 byte address of the account whose asset slot is being frozen or un-frozen.

Only set when type_enum() is TxnType.AssetFreeze.

For more information, see https://developer.algorand.org/docs/reference/transactions/#freezeaccount

freeze_asset_frozen() → pyteal.TxnExpr

Get the new frozen value for the asset.

Only set when type_enum() is TxnType.AssetFreeze.

For more information, see https://developer.algorand.org/docs/reference/transactions/#assetfrozen

group_index() → pyteal.TxnExpr

Get the position of the transaction within the atomic transaction group.

A stand-alone transaction is implictly element 0 in a group of 1.

For more information, see https://developer.algorand.org/docs/reference/transactions/#group

last_valid() → pyteal.TxnExpr

Get the last valid round number.

For more information, see https://developer.algorand.org/docs/reference/transactions/#lastvalid

lease() → pyteal.TxnExpr

Get the transaction lease.

For more information, see https://developer.algorand.org/docs/reference/transactions/#lease

note() → pyteal.TxnExpr

Get the transaction note.

For more information, see https://developer.algorand.org/docs/reference/transactions/#note

on_completion() → pyteal.TxnExpr

Get the on completion action from the ApplicationCall portion of the transaction.

Only set when type_enum() is TxnType.ApplicationCall.

receiver() → pyteal.TxnExpr

Get the 32 byte address of the receiver.

Only set when type_enum() is TxnType.Payment.

For more information, see https://developer.algorand.org/docs/reference/transactions/#receiver

rekey_to() → pyteal.TxnExpr

Get the sender’s new 32 byte AuthAddr.

For more information, see https://developer.algorand.org/docs/reference/transactions/#rekeyto

selection_pk() → pyteal.TxnExpr

Get the VRF public key.

Only set when type_enum() is TxnType.KeyRegistration.

For more information, see https://developer.algorand.org/docs/reference/transactions/#selectionpk

sender() → pyteal.TxnExpr

Get the 32 byte address of the sender.

For more information, see https://developer.algorand.org/docs/reference/transactions/#sender

tx_id() → pyteal.TxnExpr

Get the 32 byte computed ID for the transaction.

type() → pyteal.TxnExpr

Get the type of this transaction as a byte string.

In most cases it is preferable to use type_enum() instead.

For more information, see https://developer.algorand.org/docs/reference/transactions/#type

type_enum() → pyteal.TxnExpr

Get the type of this transaction.

See TxnType for possible values.

vote_first() → pyteal.TxnExpr

Get the first round that the participation key is valid.

Only set when type_enum() is TxnType.KeyRegistration.

For more information, see https://developer.algorand.org/docs/reference/transactions/#votefirst

vote_key_dilution() → pyteal.TxnExpr

Get the dilution for the 2-level participation key.

Only set when type_enum() is TxnType.KeyRegistration.

For more information, see https://developer.algorand.org/docs/reference/transactions/#votekeydilution

vote_last() → pyteal.TxnExpr

Get the last round that the participation key is valid.

Only set when type_enum() is TxnType.KeyRegistration.

For more information, see https://developer.algorand.org/docs/reference/transactions/#votelast

vote_pk() → pyteal.TxnExpr

Get the root participation public key.

Only set when type_enum() is TxnType.KeyRegistration.

For more information, see https://developer.algorand.org/docs/reference/transactions/#votepk

xfer_asset() → pyteal.TxnExpr

Get the ID of the asset being transferred.

Only set when type_enum() is TxnType.AssetTransfer.

For more information, see https://developer.algorand.org/docs/reference/transactions/#xferasset

class pyteal.GtxnExpr(txnIndex: int, field: pyteal.TxnField)

Bases: pyteal.TxnExpr

An expression that accesses a transaction field from a transaction in the current group.

class pyteal.GtxnaExpr(txnIndex: int, field: pyteal.TxnField, index: int)

Bases: pyteal.TxnaExpr

An expression that accesses a transaction array field from a transaction in the current group.

class pyteal.TxnGroup

Bases: object

Represents a group of transactions.

__getitem__(txnIndex: int) → pyteal.TxnObject
class pyteal.Global(field: pyteal.GlobalField)

Bases: pyteal.LeafExpr

An expression that accesses a global property.

classmethod current_application_id() → pyteal.Global

Get the ID of the current application executing.

Fails if no application is executing.

classmethod group_size() → pyteal.Global

Get the number of transactions in this atomic transaction group.

This will be at least 1.

classmethod latest_timestamp() → pyteal.Global

Get the latest confirmed block UNIX timestamp.

Fails if negative.

classmethod logic_sig_version() → pyteal.Global

Get the maximum supported TEAL version.

classmethod max_txn_life() → pyteal.Global

Get the maximum number of rounds a transaction can have.

classmethod min_balance() → pyteal.Global

Get the minumum balance in micro Algos.

classmethod min_txn_fee() → pyteal.Global

Get the minumum transaction fee in micro Algos.

classmethod round() → pyteal.Global

Get the current round number.

type_of()

Get the return type of this expression.

classmethod zero_address() → pyteal.Global

Get the 32 byte zero address.

class pyteal.GlobalField(id: int, name: str, type: pyteal.TealType)

Bases: enum.Enum

An enumeration.

current_app_id = (8, 'CurrentApplicationID', <TealType.uint64: 0>)
group_size = (4, 'GroupSize', <TealType.uint64: 0>)
latest_timestamp = (7, 'LatestTimestamp', <TealType.uint64: 0>)
logic_sig_version = (5, 'LogicSigVersion', <TealType.uint64: 0>)
max_txn_life = (2, 'MaxTxnLife', <TealType.uint64: 0>)
min_balance = (1, 'MinBalance', <TealType.uint64: 0>)
min_txn_fee = (0, 'MinTxnFee', <TealType.uint64: 0>)
round = (6, 'Round', <TealType.uint64: 0>)
type_of() → pyteal.TealType
zero_address = (3, 'ZeroAddress', <TealType.bytes: 1>)
class pyteal.App(field: pyteal.AppField, args)

Bases: pyteal.LeafExpr

An expression related to applications.

classmethod globalDel(key: pyteal.Expr) → pyteal.App

Delete a key from the global state of the current application.

Parameters:key – The key to delete from the global application state. Must evaluate to bytes.
classmethod globalGet(key: pyteal.Expr) → pyteal.App

Read from the global state of the current application.

Parameters:key – The key to read from the global application state. Must evaluate to bytes.
classmethod globalGetEx(app: pyteal.Expr, key: pyteal.Expr) → pyteal.MaybeValue

Read from the global state of an application.

Parameters:
  • app – An index into Txn.ForeignApps that corresponds to the application to read from. Must evaluate to uint64.
  • key – The key to read from the global application state. Must evaluate to bytes.
classmethod globalPut(key: pyteal.Expr, value: pyteal.Expr) → pyteal.App

Write to the global state of the current application.

Parameters:
  • key – The key to write in the global application state. Must evaluate to bytes.
  • value – THe value to write in the global application state. Can evaluate to any type.
classmethod id() → pyteal.Global

Get the ID of the current running application.

This is the same as Global.current_application_id().

classmethod localDel(account: pyteal.Expr, key: pyteal.Expr) → pyteal.App

Delete a key from an account’s local state for the current application.

Parameters:
  • account – An index into Txn.Accounts that corresponds to the account from which the key should be deleted. Must evaluate to uint64.
  • key – The key to delete from the account’s local state. Must evaluate to bytes.
classmethod localGet(account: pyteal.Expr, key: pyteal.Expr) → pyteal.App

Read from an account’s local state for the current application.

Parameters:
  • account – An index into Txn.Accounts that corresponds to the account to read from. Must evaluate to uint64.
  • key – The key to read from the account’s local state. Must evaluate to bytes.
classmethod localGetEx(account: pyteal.Expr, app: pyteal.Expr, key: pyteal.Expr) → pyteal.MaybeValue

Read from an account’s local state for an application.

Parameters:
  • account – An index into Txn.Accounts that corresponds to the account to read from. Must evaluate to uint64.
  • app – The ID of the application being checked. Must evaluate to uint64.
  • key – The key to read from the account’s local state. Must evaluate to bytes.
classmethod localPut(account: pyteal.Expr, key: pyteal.Expr, value: pyteal.Expr) → pyteal.App

Write to an account’s local state for the current application.

Parameters:
  • account – An index into Txn.Accounts that corresponds to the account to write to. Must evaluate to uint64.
  • key – The key to write in the account’s local state. Must evaluate to bytes.
  • value – The value to write in the account’s local state. Can evaluate to any type.
classmethod optedIn(account: pyteal.Expr, app: pyteal.Expr) → pyteal.App

Check if an account has opted in for an application.

Parameters:
  • account – An index into Txn.Accounts that corresponds to the account to check. Must evaluate to uint64.
  • app – The ID of the application being checked. Must evaluate to uint64.
type_of()

Get the return type of this expression.

class pyteal.AppField(op: pyteal.Op, type: pyteal.TealType)

Bases: enum.Enum

Enum of app fields used to create App objects.

get_op() → pyteal.Op
globalDel = (<Op.app_global_del: 'app_global_del'>, <TealType.none: 3>)
globalGet = (<Op.app_global_get: 'app_global_get'>, <TealType.anytype: 2>)
globalGetEx = (<Op.app_global_get_ex: 'app_global_get_ex'>, <TealType.none: 3>)
globalPut = (<Op.app_global_put: 'app_global_put'>, <TealType.none: 3>)
localDel = (<Op.app_local_del: 'app_local_del'>, <TealType.none: 3>)
localGet = (<Op.app_local_get: 'app_local_get'>, <TealType.anytype: 2>)
localGetEx = (<Op.app_local_get_ex: 'app_local_get_ex'>, <TealType.none: 3>)
localPut = (<Op.app_local_put: 'app_local_put'>, <TealType.none: 3>)
optedIn = (<Op.app_opted_in: 'app_opted_in'>, <TealType.uint64: 0>)
type_of() → pyteal.TealType
class pyteal.OnComplete

Bases: object

An enum of values that TxnObject.on_completion() may return.

ClearState = <pyteal.EnumInt object>
CloseOut = <pyteal.EnumInt object>
DeleteApplication = <pyteal.EnumInt object>
NoOp = <pyteal.EnumInt object>
OptIn = <pyteal.EnumInt object>
UpdateApplication = <pyteal.EnumInt object>
class pyteal.AssetHolding

Bases: object

classmethod balance(account: pyteal.Expr, asset: pyteal.Expr) → pyteal.MaybeValue

Get the amount of an asset held by an account.

Parameters:
  • account – An index into Txn.Accounts that corresponds to the account to check. Must evaluate to uint64.
  • asset – The ID of the asset to get. Must evaluate to uint64.
classmethod frozen(account: pyteal.Expr, asset: pyteal.Expr) → pyteal.MaybeValue

Check if an asset is frozen for an account.

Parameters:
  • account – An index into Txn.Accounts that corresponds to the account to check. Must evaluate to uint64.
  • asset – The ID of the asset to check. Must evaluate to uint64.
class pyteal.AssetParam

Bases: object

classmethod clawback(asset: pyteal.Expr) → pyteal.MaybeValue

Get the clawback address for an asset.

Parameters:asset – An index into Txn.ForeignAssets that corresponds to the asset to check. Must evaluate to uint64.
classmethod decimals(asset: pyteal.Expr) → pyteal.MaybeValue

Get the number of decimals for an asset.

Parameters:asset – An index into Txn.ForeignAssets that corresponds to the asset to check. Must evaluate to uint64.
classmethod defaultFrozen(asset: pyteal.Expr) → pyteal.MaybeValue

Check if an asset is frozen by default.

Parameters:asset – An index into Txn.ForeignAssets that corresponds to the asset to check. Must evaluate to uint64.
classmethod freeze(asset: pyteal.Expr) → pyteal.MaybeValue

Get the freeze address for an asset.

Parameters:asset – An index into Txn.ForeignAssets that corresponds to the asset to check. Must evaluate to uint64.
classmethod manager(asset: pyteal.Expr) → pyteal.MaybeValue

Get the manager commitment for an asset.

Parameters:asset – An index into Txn.ForeignAssets that corresponds to the asset to check. Must evaluate to uint64.
classmethod metadataHash(asset: pyteal.Expr) → pyteal.MaybeValue

Get the arbitrary commitment for an asset.

Parameters:asset – An index into Txn.ForeignAssets that corresponds to the asset to check. Must evaluate to uint64.
classmethod name(asset: pyteal.Expr) → pyteal.MaybeValue

Get the name of an asset.

Parameters:asset – An index into Txn.ForeignAssets that corresponds to the asset to check. Must evaluate to uint64.
classmethod reserve(asset: pyteal.Expr) → pyteal.MaybeValue

Get the reserve address for an asset.

Parameters:asset – An index into Txn.ForeignAssets that corresponds to the asset to check. Must evaluate to uint64.
classmethod total(asset: pyteal.Expr) → pyteal.MaybeValue

Get the total number of units of an asset.

Parameters:asset – An index into Txn.ForeignAssets that corresponds to the asset to check. Must evaluate to uint64.
classmethod unitName(asset: pyteal.Expr) → pyteal.MaybeValue

Get the unit name of an asset.

Parameters:asset – An index into Txn.ForeignAssets that corresponds to the asset to check. Must evaluate to uint64.
classmethod url(asset: pyteal.Expr) → pyteal.MaybeValue

Get the URL of an asset.

Parameters:asset – An index into Txn.ForeignAssets that corresponds to the asset to check. Must evaluate to uint64.
class pyteal.Array

Bases: abc.ABC

Represents a variable length array of objects.

__getitem__(index: int)

Get the value at a given index in this array.

length() → pyteal.Expr

Get the length of the array.

class pyteal.Tmpl(op: pyteal.Op, type: pyteal.TealType, name: str)

Bases: pyteal.LeafExpr

Template expression for creating placeholder values.

classmethod Addr(placeholder: str)

Create a new Addr template.

Parameters:placeholder – The name to use for this template variable. Must start with TMPL_ and only consist of uppercase alphanumeric characters and underscores.
classmethod Bytes(placeholder: str)

Create a new Bytes template.

Parameters:placeholder – The name to use for this template variable. Must start with TMPL_ and only consist of uppercase alphanumeric characters and underscores.
classmethod Int(placeholder: str)

Create a new Int template.

Parameters:placeholder – The name to use for this template variable. Must start with TMPL_ and only consist of uppercase alphanumeric characters and underscores.
type_of()

Get the return type of this expression.

class pyteal.Nonce(base: str, nonce: str, child: pyteal.Expr)

Bases: pyteal.Expr

A meta expression only used to change the hash of a TEAL program.

__init__(base: str, nonce: str, child: pyteal.Expr) → None

Create a new Nonce.

The Nonce expression behaves exactly like the child expression passed into it, except it uses the provided nonce string to alter its structure in a way that does not affect execution.

Parameters:
  • base – The base of the nonce. Must be one of utf8, base16, base32, or base64.
  • nonce – An arbitrary nonce string that conforms to base.
  • child – The expression to wrap.
type_of()

Get the return type of this expression.

class pyteal.UnaryExpr(op: pyteal.Op, inputType: pyteal.TealType, outputType: pyteal.TealType, arg: pyteal.Expr)

Bases: pyteal.Expr

An expression with a single argument.

type_of()

Get the return type of this expression.

pyteal.Btoi(arg: pyteal.Expr) → pyteal.UnaryExpr

Convert a byte string to a uint64.

pyteal.Itob(arg: pyteal.Expr) → pyteal.UnaryExpr

Convert a uint64 string to a byte string.

pyteal.Len(arg: pyteal.Expr) → pyteal.UnaryExpr

Get the length of a byte string.

pyteal.Sha256(arg: pyteal.Expr) → pyteal.UnaryExpr

Get the SHA-256 hash of a byte string.

pyteal.Sha512_256(arg: pyteal.Expr) → pyteal.UnaryExpr

Get the SHA-512/256 hash of a byte string.

pyteal.Keccak256(arg: pyteal.Expr) → pyteal.UnaryExpr

Get the KECCAK-256 hash of a byte string.

pyteal.Not(arg: pyteal.Expr) → pyteal.UnaryExpr

Get the logical inverse of a uint64.

If the argument is 0, then this will produce 1. Otherwise this will produce 0.

pyteal.BitwiseNot(arg: pyteal.Expr) → pyteal.UnaryExpr

Get the bitwise inverse of a uint64.

Produces ~arg.

pyteal.Pop(arg: pyteal.Expr) → pyteal.UnaryExpr

Pop a value from the stack.

pyteal.Return(arg: pyteal.Expr) → pyteal.UnaryExpr

Immediately exit the program with the given success value.

pyteal.Balance(arg: pyteal.Expr) → pyteal.UnaryExpr

Get the balance of a user in micro Algos.

Argument must be an index into Txn.Accounts that corresponds to the account to read from. It must evaluate to uint64.

This operation is only permitted in application mode.

class pyteal.BinaryExpr(op: pyteal.Op, inputType: pyteal.TealType, outputType: pyteal.TealType, argLeft: pyteal.Expr, argRight: pyteal.Expr)

Bases: pyteal.Expr

An expression with two arguments.

type_of()

Get the return type of this expression.

pyteal.Add(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Add two numbers.

Produces left + right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
pyteal.Minus(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Subtract two numbers.

Produces left - right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
pyteal.Mul(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Multiply two numbers.

Produces left * right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
pyteal.Div(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Divide two numbers.

Produces left / right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
pyteal.BitwiseAnd(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Bitwise and expression.

Produces left & right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
pyteal.BitwiseOr(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Bitwise or expression.

Produces left | right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
pyteal.BitwiseXor(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Bitwise xor expression.

Produces left ^ right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
pyteal.Mod(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Modulo expression.

Produces left % right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
pyteal.Eq(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Equality expression.

Checks if left == right.

Parameters:
  • left – A value to check.
  • right – The other value to check. Must evaluate to the same type as left.
pyteal.Neq(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Difference expression.

Checks if left != right.

Parameters:
  • left – A value to check.
  • right – The other value to check. Must evaluate to the same type as left.
pyteal.Lt(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Less than expression.

Checks if left < right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
pyteal.Le(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Less than or equal to expression.

Checks if left <= right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
pyteal.Gt(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Greater than expression.

Checks if left > right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
pyteal.Ge(left: pyteal.Expr, right: pyteal.Expr) → pyteal.BinaryExpr

Greater than or equal to expression.

Checks if left >= right.

Parameters:
  • left – Must evaluate to uint64.
  • right – Must evaluate to uint64.
class pyteal.Ed25519Verify(data: pyteal.Expr, sig: pyteal.Expr, key: pyteal.Expr)

Bases: pyteal.Expr

An expression to verify ed25519 signatures.

__init__(data: pyteal.Expr, sig: pyteal.Expr, key: pyteal.Expr) → None

Verify the ed25519 signature of (“ProgData” || program_hash || data).

Parameters:
  • data – The data signed by the public. Must evalutes to bytes.
  • sig – The proposed 64 byte signature of (“ProgData” || program_hash || data). Must evalute to bytes.
  • key – The 32 byte public key that produced the signature. Must evaluate to bytes.
type_of()

Get the return type of this expression.

class pyteal.Substring(string: pyteal.Expr, start: pyteal.Expr, end: pyteal.Expr)

Bases: pyteal.Expr

Take a substring of a byte string.

__init__(string: pyteal.Expr, start: pyteal.Expr, end: pyteal.Expr) → None

Create a new Substring expression.

Produces a new byte string consisting of the bytes starting at start up to but not including end.

Parameters:
  • string – The byte string.
  • start – The starting index for the substring.
  • end – The ending index for the substring.
type_of()

Get the return type of this expression.

class pyteal.NaryExpr(op: pyteal.Op, inputType: pyteal.TealType, outputType: pyteal.TealType, args: Sequence[pyteal.Expr])

Bases: pyteal.Expr

N-ary expression base class.

This type of expression takes an arbitrary number of arguments.

type_of()

Get the return type of this expression.

pyteal.And(*args) → pyteal.NaryExpr

Logical and expression.

Produces 1 if all arguments are nonzero. Otherwise produces 0.

All arguments must be PyTeal expressions that evaluate to uint64, and there must be at least two arguments.

Example

And(Txn.amount() == Int(500), Txn.fee() <= Int(10))

pyteal.Or(*args) → pyteal.NaryExpr

Logical or expression.

Produces 1 if any argument is nonzero. Otherwise produces 0.

All arguments must be PyTeal expressions that evaluate to uint64, and there must be at least two arguments.

pyteal.Concat(*args) → pyteal.NaryExpr

Concatenate byte strings.

Produces a new byte string consisting of the contents of each of the passed in byte strings joined together.

All arguments must be PyTeal expressions that evaluate to bytes, and there must be at least two arguments.

Example

Concat(Bytes("hello"), Bytes(" "), Bytes("world"))

class pyteal.If(cond: pyteal.Expr, thenBranch: pyteal.Expr, elseBranch: pyteal.Expr = None)

Bases: pyteal.Expr

Simple two-way conditional expression.

__init__(cond: pyteal.Expr, thenBranch: pyteal.Expr, elseBranch: pyteal.Expr = None) → None

Create a new If expression.

When this If expression is executed, the condition will be evaluated, and if it produces a true value, thenBranch will be executed and used as the return value for this expression. Otherwise, elseBranch will be executed and used as the return value, if it is provided.

Parameters:
  • cond – The condition to check. Must evaluate to uint64.
  • thenBranch – Expression to evaluate if the condition is true.
  • elseBranch (optional) – Expression to evaluate if the condition is false. Must evaluate to the same type as thenBranch, if provided. Defaults to None.
type_of()

Get the return type of this expression.

class pyteal.Cond(*argv)

Bases: pyteal.Expr

A chainable branching expression that supports an arbitrary number of conditions.

__init__(*argv)

Create a new Cond expression.

At least one argument must be provided, and each argument must be a list with two elements. The first element is a condition which evalutes to uint64, and the second is the body of the condition, which will execute if that condition is true. All condition bodies must have the same return type. During execution, each condition is tested in order, and the first condition to evaluate to a true value will cause its associated body to execute and become the value for this Cond expression. If no condition evalutes to a true value, the Cond expression produces an error and the TEAL program terminates.

Example

Cond([Global.group_size() == Int(5), bid],
    [Global.group_size() == Int(4), redeem],
    [Global.group_size() == Int(1), wrapup])
type_of()

Get the return type of this expression.

class pyteal.Seq(exprs: List[pyteal.Expr])

Bases: pyteal.Expr

A control flow expression to represent a sequence of expressions.

__init__(exprs: List[pyteal.Expr])

Create a new Seq expression.

The new Seq expression will take on the return value of the final expression in the sequence.

Parameters:exprs – The expressions to include in this sequence. All expressions that are not the final one in this list must not return any values.

Example

Seq([
    App.localPut(Bytes("key"), Bytes("value")),
    Int(1)
])
type_of()

Get the return type of this expression.

class pyteal.Assert(cond: pyteal.Expr)

Bases: pyteal.Expr

A control flow expression to verify that a condition is true.

__init__(cond: pyteal.Expr) → None

Create an assert statement that raises an error if the condition is false.

Parameters:cond – The condition to check. Must evaluate to a uint64.
type_of()

Get the return type of this expression.

class pyteal.ScratchSlot

Bases: object

Represents the allocation of a scratch space slot.

load(type: pyteal.TealType = <TealType.anytype: 2>) → pyteal.ScratchLoad

Get an expression to load a value from this slot.

Parameters:type (optional) – The type being loaded from this slot, if known. Defaults to TealType.anytype.
slotId = 0
store(value: pyteal.Expr = None) → pyteal.Expr

Get an expression to store a value in this slot.

Parameters:
  • value (optional) – The value to store in this slot. If not included, the last value on
  • stack will be stored. NOTE (the) – storing the last value on the stack breaks the typical
  • of PyTeal, only use if you know what you're doing. (semantics) –
class pyteal.ScratchLoad(slot: pyteal.ScratchSlot, type: pyteal.TealType = <TealType.anytype: 2>)

Bases: pyteal.Expr

Expression to load a value from scratch space.

__init__(slot: pyteal.ScratchSlot, type: pyteal.TealType = <TealType.anytype: 2>)

Create a new ScratchLoad expression.

Parameters:
  • slot – The slot to load the value from.
  • type (optional) – The type being loaded from this slot, if known. Defaults to TealType.anytype.
type_of()

Get the return type of this expression.

class pyteal.ScratchStore(slot: pyteal.ScratchSlot, value: pyteal.Expr)

Bases: pyteal.Expr

Expression to store a value in scratch space.

__init__(slot: pyteal.ScratchSlot, value: pyteal.Expr)

Create a new ScratchStore expression.

Parameters:
  • slot – The slot to store the value in.
  • value – The value to store.
type_of()

Get the return type of this expression.

class pyteal.ScratchStackStore(slot: pyteal.ScratchSlot)

Bases: pyteal.Expr

Expression to store a value from the stack in scratch space.

NOTE: This expression breaks the typical semantics of PyTeal, only use if you know what you’re doing.

__init__(slot: pyteal.ScratchSlot)

Create a new ScratchStackStore expression.

Parameters:slot – The slot to store the value in.
type_of()

Get the return type of this expression.

class pyteal.ScratchVar(type: pyteal.TealType = <TealType.anytype: 2>)

Bases: object

Interface around Scratch space, similiar to get/put local/global state

Example

myvar = ScratchVar(TealType.uint64)
Seq([
    myvar.store(Int(5)),
    Assert(myvar.load() == Int(5))
])
__init__(type: pyteal.TealType = <TealType.anytype: 2>)

Create a new ScratchVar with an optional type.

Parameters:type (optional) – The type that this variable can hold. An error will be thrown if an expression with an incompatiable type is stored in this variable. Defaults to TealType.anytype.
load() → pyteal.ScratchLoad

Load value from Scratch Space

storage_type() → pyteal.TealType

Get the type of expressions that can be stored in this ScratchVar.

store(value: pyteal.Expr) → pyteal.Expr

Store value in Scratch Space

Parameters:value – The value to store. Must conform to this ScratchVar’s type.
class pyteal.MaybeValue(op: pyteal.Op, type: pyteal.TealType, *, immediate_args: List[Union[int, str]] = None, args: List[pyteal.Expr] = None)

Bases: pyteal.LeafExpr

Represents a get operation returning a value that may not exist.

__init__(op: pyteal.Op, type: pyteal.TealType, *, immediate_args: List[Union[int, str]] = None, args: List[pyteal.Expr] = None)

Create a new MaybeValue.

Parameters:
  • op – The operation that returns values.
  • type – The type of the returned value.
  • immediate_args (optional) – Immediate arguments for the op. Defaults to None.
  • args (optional) – Stack arguments for the op. Defaults to None.
hasValue() → pyteal.ScratchLoad

Check if the value exists.

This will return 1 if the value exists, otherwise 0.

type_of()

Get the return type of this expression.

value() → pyteal.ScratchLoad

Get the value.

If the value exists, it will be returned. Otherwise, the zero value for this type will be returned (i.e. either 0 or an empty byte string, depending on the type).

class pyteal.Op(value: str, mode: pyteal.Mode)

Bases: enum.Enum

Enum of program opcodes.

add = '+'
addr = 'addr'
addw = 'addw'
app_global_del = 'app_global_del'
app_global_get = 'app_global_get'
app_global_get_ex = 'app_global_get_ex'
app_global_put = 'app_global_put'
app_local_del = 'app_local_del'
app_local_get = 'app_local_get'
app_local_get_ex = 'app_local_get_ex'
app_local_put = 'app_local_put'
app_opted_in = 'app_opted_in'
arg = 'arg'
asset_holding_get = 'asset_holding_get'
asset_params_get = 'asset_params_get'
b = 'b'
balance = 'balance'
bitwise_and = '&'
bitwise_not = '~'
bitwise_or = '|'
bitwise_xor = '^'
bnz = 'bnz'
btoi = 'btoi'
byte = 'byte'
bz = 'bz'
concat = 'concat'
div = '/'
dup = 'dup'
dup2 = 'dup2'
ed25519verify = 'ed25519verify'
eq = '=='
err = 'err'
ge = '>='
global_ = 'global'
gt = '>'
gtxn = 'gtxn'
gtxna = 'gtxna'
int = 'int'
itob = 'itob'
keccak256 = 'keccak256'
le = '<='
len = 'len'
load = 'load'
logic_and = '&&'
logic_not = '!'
logic_or = '||'
lt = '<'
minus = '-'
mod = '%'
mul = '*'
mulw = 'mulw'
neq = '!='
pop = 'pop'
return_ = 'return'
sha256 = 'sha256'
sha512_256 = 'sha512_256'
store = 'store'
substring = 'substring'
substring3 = 'substring3'
txn = 'txn'
txna = 'txna'
class pyteal.Mode

Bases: enum.Flag

Enum of program running modes.

Application = 2
Signature = 1
class pyteal.TealComponent

Bases: abc.ABC

assemble() → str
assignSlot(slot: ScratchSlot, location: int)
getSlots() → List[ScratchSlot]
class pyteal.TealOp(op: pyteal.Op, *args)

Bases: pyteal.TealComponent

assemble() → str
assignSlot(slot: ScratchSlot, location: int)
getOp() → pyteal.Op
getSlots() → List[ScratchSlot]
class pyteal.TealLabel(label: str)

Bases: pyteal.TealComponent

assemble() → str
class pyteal.TealBlock(ops: List[pyteal.TealOp])

Bases: abc.ABC

Represents a basic block of TealComponents in a graph.

classmethod FromOp(op: pyteal.TealOp, *args) → Tuple[TealBlock, TealSimpleBlock]

Create a path of blocks from a TealOp and its arguments.

Returns:The starting and ending block of the path that encodes the given TealOp and arguments.
classmethod Iterate(start: pyteal.TealBlock) → Iterator[pyteal.TealBlock]

Perform a depth-first search of the graph of blocks starting with start.

classmethod NormalizeBlocks(start: pyteal.TealBlock) → pyteal.TealBlock

Minimize the number of blocks in the graph of blocks starting with start by combining sequential blocks. This operation does not alter the operations of the graph or the functionality of its underlying program, however it does mutate the input graph.

Returns:The new starting point of the altered graph. May be the same or differant than start.
addIncoming(block: Optional[pyteal.TealBlock] = None) → None

Calculate the parent blocks for this block and its children.

Parameters:block (optional) – The parent block to this one, if it has one. Defaults to None.
getOutgoing() → List[pyteal.TealBlock]

Get this block’s children blocks, if any.

isTerminal() → bool

Check if this block ends the program.

replaceOutgoing(oldBlock: pyteal.TealBlock, newBlock: pyteal.TealBlock) → None

Replace one of this block’s child blocks.

validate(parent: Optional[pyteal.TealBlock] = None) → None

Check that this block and its children have valid parent pointers.

Parameters:parent (optional) – The parent block to this one, if it has one. Defaults to None.
class pyteal.TealSimpleBlock(ops: List[pyteal.TealOp])

Bases: pyteal.TealBlock

Represents a basic block of TealComponents in a graph that does not contain a branch condition.

getOutgoing() → List[pyteal.TealBlock]

Get this block’s children blocks, if any.

replaceOutgoing(oldBlock: pyteal.TealBlock, newBlock: pyteal.TealBlock) → None

Replace one of this block’s child blocks.

setNextBlock(block: pyteal.TealBlock) → None

Set the block that follows this one.

class pyteal.TealConditionalBlock(ops: List[pyteal.TealOp])

Bases: pyteal.TealBlock

Represents a basic block of TealComponents in a graph ending with a branch condition.

getOutgoing() → List[pyteal.TealBlock]

Get this block’s children blocks, if any.

replaceOutgoing(oldBlock: pyteal.TealBlock, newBlock: pyteal.TealBlock) → None

Replace one of this block’s child blocks.

setFalseBlock(block: pyteal.TealBlock) → None

Set the block that this one should branch to if its condition is false.

setTrueBlock(block: pyteal.TealBlock) → None

Set the block that this one should branch to if its condition is true.

pyteal.compileTeal(ast: pyteal.Expr, mode: pyteal.Mode) → str

Compile a PyTeal expression into TEAL assembly.

Parameters:
  • ast – The PyTeal expression to assemble.
  • mode – The mode of the program to assemble. Must be Signature or Application.
Returns:

A TEAL assembly program compiled from the input expression.

Raises:

TealInputError – if an operation in ast is not supported by the supplied mode.

class pyteal.TealType

Bases: enum.Enum

Teal type enum.

anytype = 2
bytes = 1
none = 3
uint64 = 0
exception pyteal.TealInternalError(message: str)

Bases: Exception

exception pyteal.TealTypeError(actual, expected)

Bases: Exception

exception pyteal.TealInputError(msg)

Bases: Exception

pyteal.execute(args)

Execute in bash, return stdout and stderr in string

Arguments: args: command and arguments to run, e.g. [‘ls’, ‘-l’]