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.
-
getDefinitionTrace
() → List[str]¶
-
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, min_version: int)¶ Bases:
enum.Enum
An enumeration.
-
accounts
= (28, 'Accounts', <TealType.bytes: 1>, 2)¶
-
amount
= (8, 'Amount', <TealType.uint64: 0>, 2)¶
-
application_args
= (26, 'ApplicationArgs', <TealType.bytes: 1>, 2)¶
-
application_id
= (24, 'ApplicationID', <TealType.uint64: 0>, 2)¶
-
applications
= (50, 'Applications', <TealType.uint64: 0>, 3)¶
-
approval_program
= (30, 'ApprovalProgram', <TealType.bytes: 1>, 2)¶
-
asset_amount
= (18, 'AssetAmount', <TealType.uint64: 0>, 2)¶
-
asset_close_to
= (21, 'AssetCloseTo', <TealType.bytes: 1>, 2)¶
-
asset_receiver
= (20, 'AssetReceiver', <TealType.bytes: 1>, 2)¶
-
asset_sender
= (19, 'AssetSender', <TealType.bytes: 1>, 2)¶
-
assets
= (48, 'Assets', <TealType.uint64: 0>, 3)¶
-
clear_state_program
= (31, 'ClearStateProgram', <TealType.bytes: 1>, 2)¶
-
close_remainder_to
= (9, 'CloseRemainderTo', <TealType.bytes: 1>, 2)¶
-
config_asset
= (33, 'ConfigAsset', <TealType.uint64: 0>, 2)¶
-
config_asset_clawback
= (44, 'ConfigAssetClawback', <TealType.bytes: 1>, 2)¶
-
config_asset_decimals
= (35, 'ConfigAssetDecimals', <TealType.uint64: 0>, 2)¶
-
config_asset_default_frozen
= (36, 'ConfigAssetDefaultFrozen', <TealType.uint64: 0>, 2)¶
-
config_asset_freeze
= (43, 'ConfigAssetFreeze', <TealType.bytes: 1>, 2)¶
-
config_asset_manager
= (41, 'ConfigAssetManager', <TealType.bytes: 1>, 2)¶
-
config_asset_metadata_hash
= (40, 'ConfigAssetMetadataHash', <TealType.bytes: 1>, 2)¶
-
config_asset_name
= (38, 'ConfigAssetName', <TealType.bytes: 1>, 2)¶
-
config_asset_reserve
= (42, 'ConfigAssetReserve', <TealType.bytes: 1>, 2)¶
-
config_asset_total
= (34, 'ConfigAssetTotal', <TealType.uint64: 0>, 2)¶
-
config_asset_unit_name
= (37, 'ConfigAssetUnitName', <TealType.bytes: 1>, 2)¶
-
config_asset_url
= (39, 'ConfigAssetURL', <TealType.bytes: 1>, 2)¶
-
fee
= (1, 'Fee', <TealType.uint64: 0>, 2)¶
-
first_valid
= (2, 'FirstValid', <TealType.uint64: 0>, 2)¶
-
first_valid_time
= (3, 'FirstValidTime', <TealType.uint64: 0>, 2)¶
-
freeze_asset
= (45, 'FreezeAsset', <TealType.uint64: 0>, 2)¶
-
freeze_asset_account
= (46, 'FreezeAssetAccount', <TealType.bytes: 1>, 2)¶
-
freeze_asset_frozen
= (47, 'FreezeAssetFrozen', <TealType.uint64: 0>, 2)¶
-
global_num_byte_slices
= (53, 'GlobalNumByteSlice', <TealType.uint64: 0>, 3)¶
-
global_num_uints
= (52, 'GlobalNumUint', <TealType.uint64: 0>, 3)¶
-
group_index
= (22, 'GroupIndex', <TealType.uint64: 0>, 2)¶
-
last_valid
= (4, 'LastValid', <TealType.uint64: 0>, 2)¶
-
lease
= (6, 'Lease', <TealType.bytes: 1>, 2)¶
-
local_num_byte_slices
= (55, 'LocalNumByteSlice', <TealType.uint64: 0>, 3)¶
-
local_num_uints
= (54, 'LocalNumUint', <TealType.uint64: 0>, 3)¶
-
note
= (5, 'Note', <TealType.bytes: 1>, 2)¶
-
num_accounts
= (2, 'NumAccounts', <TealType.uint64: 0>, 2)¶
-
num_app_args
= (27, 'NumAppArgs', <TealType.uint64: 0>, 2)¶
-
num_applications
= (51, 'NumApplications', <TealType.uint64: 0>, 3)¶
-
num_assets
= (49, 'NumAssets', <TealType.uint64: 0>, 3)¶
-
on_completion
= (25, 'OnCompletion', <TealType.uint64: 0>, 2)¶
-
receiver
= (7, 'Receiver', <TealType.bytes: 1>, 2)¶
-
rekey_to
= (32, 'RekeyTo', <TealType.bytes: 1>, 2)¶
-
selection_pk
= (11, 'SelectionPK', <TealType.bytes: 1>, 2)¶
-
sender
= (0, 'Sender', <TealType.bytes: 1>, 2)¶
-
tx_id
= (23, 'TxID', <TealType.bytes: 1>, 2)¶
-
type
= (15, 'Type', <TealType.bytes: 1>, 2)¶
-
type_enum
= (16, 'TypeEnum', <TealType.uint64: 0>, 2)¶
-
type_of
() → pyteal.TealType¶
-
vote_first
= (12, 'VoteFirst', <TealType.uint64: 0>, 2)¶
-
vote_key_dilution
= (14, 'VoteKeyDilution', <TealType.uint64: 0>, 2)¶
-
vote_last
= (13, 'VoteLast', <TealType.uint64: 0>, 2)¶
-
vote_pk
= (10, 'VotePK', <TealType.bytes: 1>, 2)¶
-
xfer_asset
= (17, 'XferAsset', <TealType.uint64: 0>, 2)¶
-
-
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.
-
amount
() → pyteal.TxnExpr¶ Get the amount of the transaction in micro Algos.
Only set when
type_enum()
isTxnType.Payment
.For more information, see https://developer.algorand.org/docs/reference/transactions/#amount
-
application_id
() → pyteal.TxnExpr¶ Get the application ID from the ApplicationCall portion of the current transaction.
Only set when
type_enum()
isTxnType.ApplicationCall
.
-
applications
¶ The applications array in an ApplicationCall transaction.
Type: TxnArray Requires TEAL version 3 or higher.
-
approval_program
() → pyteal.TxnExpr¶ Get the approval program.
Only set when
type_enum()
isTxnType.ApplicationCall
.
-
asset_amount
() → pyteal.TxnExpr¶ Get the amount of the asset being transferred, measured in the asset’s units.
Only set when
type_enum()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.AssetTransfer
.For more information, see https://developer.algorand.org/docs/reference/transactions/#assetsender
-
assets
¶ The foreign asset array in an ApplicationCall transaction.
Type: TxnArray Requires TEAL version 3 or higher.
-
clear_state_program
() → pyteal.TxnExpr¶ Get the clear state program.
Only set when
type_enum()
isTxnType.ApplicationCall
.
-
close_remainder_to
() → pyteal.TxnExpr¶ Get the 32 byte address of the CloseRemainderTo field.
Only set when
type_enum()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.AssetFreeze
.For more information, see https://developer.algorand.org/docs/reference/transactions/#assetfrozen
-
global_num_byte_slices
() → pyteal.TxnExpr¶ Get the schema count of global state byte slices in an application creation call.
Only set when
type_enum()
isTxnType.ApplicationCall
and this is an app creation call.Requires TEAL version 3 or higher.
-
global_num_uints
() → pyteal.TxnExpr¶ Get the schema count of global state integers in an application creation call.
Only set when
type_enum()
isTxnType.ApplicationCall
and this is an app creation call.Requires TEAL version 3 or higher.
-
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
-
local_num_byte_slices
() → pyteal.TxnExpr¶ Get the schema count of local state byte slices in an application creation call.
Only set when
type_enum()
isTxnType.ApplicationCall
and this is an app creation call.Requires TEAL version 3 or higher.
-
local_num_uints
() → pyteal.TxnExpr¶ Get the schema count of local state integers in an application creation call.
Only set when
type_enum()
isTxnType.ApplicationCall
and this is an app creation call.Requires TEAL version 3 or higher.
-
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()
isTxnType.ApplicationCall
.
-
receiver
() → pyteal.TxnExpr¶ Get the 32 byte address of the receiver.
Only set when
type_enum()
isTxnType.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()
isTxnType.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
-
vote_first
() → pyteal.TxnExpr¶ Get the first round that the participation key is valid.
Only set when
type_enum()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.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()
isTxnType.AssetTransfer
.For more information, see https://developer.algorand.org/docs/reference/transactions/#xferasset
-
-
class
pyteal.
GtxnExpr
(txnIndex: Union[int, pyteal.Expr], field: pyteal.TxnField)¶ Bases:
pyteal.TxnExpr
An expression that accesses a transaction field from a transaction in the current group.
-
class
pyteal.
GtxnaExpr
(txnIndex: Union[int, pyteal.Expr], 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: Union[int, pyteal.Expr]) → pyteal.TxnObject¶
-
-
class
pyteal.
Global
(field: pyteal.GlobalField)¶ Bases:
pyteal.LeafExpr
An expression that accesses a global property.
-
classmethod
creator_address
() → pyteal.Global¶ Address of the creator of the current application.
Fails if no such application is executing. Requires TEAL version 3 or higher.
-
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.
-
classmethod
-
class
pyteal.
GlobalField
(id: int, name: str, type: pyteal.TealType, min_version: int)¶ Bases:
enum.Enum
An enumeration.
-
creator_address
= (9, 'CreatorAddress', <TealType.bytes: 1>, 3)¶
-
current_app_id
= (8, 'CurrentApplicationID', <TealType.uint64: 0>, 2)¶
-
group_size
= (4, 'GroupSize', <TealType.uint64: 0>, 2)¶
-
latest_timestamp
= (7, 'LatestTimestamp', <TealType.uint64: 0>, 2)¶
-
logic_sig_version
= (5, 'LogicSigVersion', <TealType.uint64: 0>, 2)¶
-
max_txn_life
= (2, 'MaxTxnLife', <TealType.uint64: 0>, 2)¶
-
min_balance
= (1, 'MinBalance', <TealType.uint64: 0>, 2)¶
-
min_txn_fee
= (0, 'MinTxnFee', <TealType.uint64: 0>, 2)¶
-
round
= (6, 'Round', <TealType.uint64: 0>, 2)¶
-
type_of
() → pyteal.TealType¶
-
zero_address
= (3, 'ZeroAddress', <TealType.bytes: 1>, 2)¶
-
-
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.
-
classmethod
-
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: OpType(value='app_global_del', mode=<Mode.Application: 2>, min_version=2)>, <TealType.none: 3>)¶
-
globalGet
= (<Op.app_global_get: OpType(value='app_global_get', mode=<Mode.Application: 2>, min_version=2)>, <TealType.anytype: 2>)¶
-
globalGetEx
= (<Op.app_global_get_ex: OpType(value='app_global_get_ex', mode=<Mode.Application: 2>, min_version=2)>, <TealType.none: 3>)¶
-
globalPut
= (<Op.app_global_put: OpType(value='app_global_put', mode=<Mode.Application: 2>, min_version=2)>, <TealType.none: 3>)¶
-
localDel
= (<Op.app_local_del: OpType(value='app_local_del', mode=<Mode.Application: 2>, min_version=2)>, <TealType.none: 3>)¶
-
localGet
= (<Op.app_local_get: OpType(value='app_local_get', mode=<Mode.Application: 2>, min_version=2)>, <TealType.anytype: 2>)¶
-
localGetEx
= (<Op.app_local_get_ex: OpType(value='app_local_get_ex', mode=<Mode.Application: 2>, min_version=2)>, <TealType.none: 3>)¶
-
localPut
= (<Op.app_local_put: OpType(value='app_local_put', mode=<Mode.Application: 2>, min_version=2)>, <TealType.none: 3>)¶
-
optedIn
= (<Op.app_opted_in: OpType(value='app_opted_in', mode=<Mode.Application: 2>, min_version=2)>, <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.
A value of 1 indicates frozen and 0 indicates not frozen.
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.
-
classmethod
-
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 address 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.
If set, this will be 32 bytes long.
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.
-
classmethod
-
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.
-
classmethod
-
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
(account: pyteal.Expr) → pyteal.UnaryExpr¶ Get the balance of a user in microAlgos.
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.
-
pyteal.
MinBalance
(account: pyteal.Expr) → pyteal.UnaryExpr¶ Get the minimum balance of a user in microAlgos.
For more information about minimum balances, see: https://developer.algorand.org/docs/features/accounts/#minimum-balance
Argument must be an index into Txn.Accounts that corresponds to the account to read from. It must evaluate to uint64.
Requires TEAL version 3 or higher. This operation is only permitted in application mode.
-
class
pyteal.
BinaryExpr
(op: pyteal.Op, inputType: Union[pyteal.TealType, Tuple[pyteal.TealType, 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.
-
pyteal.
GetBit
(value: pyteal.Expr, index: pyteal.Expr) → pyteal.BinaryExpr¶ Get the bit value of an expression at a specific index.
The meaning of index differs if value is an integer or a byte string.
- For integers, bit indexing begins with low-order bits. For example,
GetBit(Int(16), Int(4))
yields 1. Any other valid index would yield a bit value of 0. Any integer less than 64 is a valid index. - For byte strings, bit indexing begins at the first byte. For example,
GetBit(Bytes("base16", "0xf0"), Int(0))
yields 1. Any index less than 4 would yield 1, and any valid index 4 or greater would yield 0. Any integer less than 8*Len(value) is a valid index.
Requires TEAL version 3 or higher.
Parameters: - value – The value containing bits. Can evaluate to any type.
- index – The index of the bit to extract. Must evaluate to uint64.
- For integers, bit indexing begins with low-order bits. For example,
-
pyteal.
GetByte
(value: pyteal.Expr, index: pyteal.Expr) → pyteal.BinaryExpr¶ Extract a single byte as an integer from a byte string.
Similar to GetBit, indexing begins at the first byte. For example,
GetByte(Bytes("base16", "0xff0000"), Int(0))
yields 255. Any other valid index would yield 0.Requires TEAL version 3 or higher.
Parameters: - value – The value containing the bytes. Must evaluate to bytes.
- index – The index of the byte to extract. Must evaluate to an integer less than Len(value).
-
pyteal.
Ed25519Verify
(data: pyteal.Expr, sig: pyteal.Expr, key: pyteal.Expr) → pyteal.TernaryExpr¶ Verify the ed25519 signature of the concatenation (“ProgData” + hash_of_current_program + data).
Parameters: - data – The data signed by the public key. Must evalutes to bytes.
- sig – The proposed 64-byte signature of the concatenation (“ProgData” + hash_of_current_program + data). Must evalute to bytes.
- key – The 32 byte public key that produced the signature. Must evaluate to bytes.
-
pyteal.
Substring
(string: pyteal.Expr, start: pyteal.Expr, end: pyteal.Expr) → pyteal.TernaryExpr¶ Take a substring of a byte string.
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. Must be an integer less than or equal to Len(string).
- end – The ending index for the substring. Must be an integer greater or equal to start, but less than or equal to Len(string).
-
pyteal.
SetBit
(value: pyteal.Expr, index: pyteal.Expr, newBitValue: pyteal.Expr) → pyteal.TernaryExpr¶ Set the bit value of an expression at a specific index.
The meaning of index differs if value is an integer or a byte string.
- For integers, bit indexing begins with low-order bits. For example,
SetBit(Int(0), Int(4), Int(1))
yields the integer 16 (2^4). Any integer less than 64 is a valid index. - For byte strings, bit indexing begins at the first byte. For example,
SetBit(Bytes("base16", "0x00"), Int(7), Int(1))
yields the byte string 0x01. Any integer less than 8*Len(value) is a valid index.
Requires TEAL version 3 or higher.
Parameters: - value – The value containing bits. Can evaluate to any type.
- index – The index of the bit to set. Must evaluate to uint64.
- newBitValue – The new bit value to set. Must evaluate to the integer 0 or 1.
- For integers, bit indexing begins with low-order bits. For example,
-
pyteal.
SetByte
(value: pyteal.Expr, index: pyteal.Expr, newByteValue: pyteal.Expr) → pyteal.TernaryExpr¶ Set a single byte in a byte string from an integer value.
Similar to SetBit, indexing begins at the first byte. For example,
SetByte(Bytes("base16", "0x000000"), Int(0), Int(255))
yields the byte string 0xff0000.Requires TEAL version 3 or higher.
Parameters: - value – The value containing the bytes. Must evaluate to bytes.
- index – The index of the byte to set. Must evaluate to an integer less than Len(value).
- newByteValue – The new byte value to set. Must evaluate to an integer less than 256.
-
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
¶ Bases:
enum.Enum
Enum of program opcodes.
-
add
= OpType(value='+', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
addr
= OpType(value='addr', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
addw
= OpType(value='addw', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
app_global_del
= OpType(value='app_global_del', mode=<Mode.Application: 2>, min_version=2)¶
-
app_global_get
= OpType(value='app_global_get', mode=<Mode.Application: 2>, min_version=2)¶
-
app_global_get_ex
= OpType(value='app_global_get_ex', mode=<Mode.Application: 2>, min_version=2)¶
-
app_global_put
= OpType(value='app_global_put', mode=<Mode.Application: 2>, min_version=2)¶
-
app_local_del
= OpType(value='app_local_del', mode=<Mode.Application: 2>, min_version=2)¶
-
app_local_get
= OpType(value='app_local_get', mode=<Mode.Application: 2>, min_version=2)¶
-
app_local_get_ex
= OpType(value='app_local_get_ex', mode=<Mode.Application: 2>, min_version=2)¶
-
app_local_put
= OpType(value='app_local_put', mode=<Mode.Application: 2>, min_version=2)¶
-
app_opted_in
= OpType(value='app_opted_in', mode=<Mode.Application: 2>, min_version=2)¶
-
arg
= OpType(value='arg', mode=<Mode.Signature: 1>, min_version=2)¶
-
assert_
= OpType(value='assert', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
asset_holding_get
= OpType(value='asset_holding_get', mode=<Mode.Application: 2>, min_version=2)¶
-
asset_params_get
= OpType(value='asset_params_get', mode=<Mode.Application: 2>, min_version=2)¶
-
b
= OpType(value='b', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
balance
= OpType(value='balance', mode=<Mode.Application: 2>, min_version=2)¶
-
bitwise_and
= OpType(value='&', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
bitwise_not
= OpType(value='~', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
bitwise_or
= OpType(value='|', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
bitwise_xor
= OpType(value='^', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
bnz
= OpType(value='bnz', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
btoi
= OpType(value='btoi', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
byte
= OpType(value='byte', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
bz
= OpType(value='bz', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
concat
= OpType(value='concat', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
dig
= OpType(value='dig', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
div
= OpType(value='/', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
dup
= OpType(value='dup', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
dup2
= OpType(value='dup2', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
ed25519verify
= OpType(value='ed25519verify', mode=<Mode.Signature: 1>, min_version=2)¶
-
eq
= OpType(value='==', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
err
= OpType(value='err', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
ge
= OpType(value='>=', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
getbit
= OpType(value='getbit', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
getbyte
= OpType(value='getbyte', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
global_
= OpType(value='global', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
gt
= OpType(value='>', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
gtxn
= OpType(value='gtxn', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
gtxna
= OpType(value='gtxna', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
gtxns
= OpType(value='gtxns', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
gtxnsa
= OpType(value='gtxnsa', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
int
= OpType(value='int', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
itob
= OpType(value='itob', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
keccak256
= OpType(value='keccak256', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
le
= OpType(value='<=', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
len
= OpType(value='len', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
load
= OpType(value='load', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
logic_and
= OpType(value='&&', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
logic_not
= OpType(value='!', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
logic_or
= OpType(value='||', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
lt
= OpType(value='<', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
min_balance
= OpType(value='min_balance', mode=<Mode.Application: 2>, min_version=3)¶
-
min_version
¶ Get the minimum version where this op is available.
-
minus
= OpType(value='-', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
mod
= OpType(value='%', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
mode
¶ Get the modes where this op is available.
-
mul
= OpType(value='*', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
mulw
= OpType(value='mulw', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
neq
= OpType(value='!=', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
pop
= OpType(value='pop', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
pushbytes
= OpType(value='pushbytes', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
pushint
= OpType(value='pushint', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
return_
= OpType(value='return', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
select
= OpType(value='select', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
setbit
= OpType(value='setbit', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
setbyte
= OpType(value='setbyte', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
sha256
= OpType(value='sha256', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
sha512_256
= OpType(value='sha512_256', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
store
= OpType(value='store', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
substring
= OpType(value='substring', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
substring3
= OpType(value='substring3', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
swap
= OpType(value='swap', mode=<Mode.Application|Signature: 3>, min_version=3)¶
-
txn
= OpType(value='txn', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
txna
= OpType(value='txna', mode=<Mode.Application|Signature: 3>, min_version=2)¶
-
-
class
pyteal.
TealComponent
(expr: Optional[Expr])¶ Bases:
abc.ABC
-
class
Context
¶ Bases:
object
-
class
EqualityContext
¶ Bases:
contextlib.AbstractContextManager
-
checkExpr
= True¶
-
classmethod
ignoreExprEquality
()¶
-
class
-
assemble
() → str¶
-
assignSlot
(slot: ScratchSlot, location: int)¶
-
getSlots
() → List[ScratchSlot]¶
-
class
-
class
pyteal.
TealOp
(expr: Optional[Expr], op: pyteal.Op, *args)¶ Bases:
pyteal.TealComponent
-
assemble
() → str¶
-
assignSlot
(slot: ScratchSlot, location: int)¶
-
getOp
() → pyteal.Op¶
-
getSlots
() → List[ScratchSlot]¶
-
-
class
pyteal.
TealLabel
(expr: Optional[Expr], 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
(options: CompileOptions, 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
(parent: Optional[pyteal.TealBlock] = None, visited: List[TealBlock] = None) → None¶ Calculate the parent blocks for this block and its children.
Parameters: - parent (optional) – The parent block to this one, if it has one. Defaults to None.
- visited (optional) – Used internally to remember blocks that have been visited. Set 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.
-
validateSlots
(slotsInUse: Set[ScratchSlot] = None, visited: Set[Tuple[int, ...]] = None) → List[pyteal.TealCompileError]¶
-
validateTree
(parent: Optional[pyteal.TealBlock] = None, visited: List[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.
- visited (optional) – Used internally to remember blocks that have been visited. Set to None.
-
classmethod
-
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.
-
-
class
pyteal.
CompileOptions
(*, mode: pyteal.Mode = <Mode.Signature: 1>, version: int = 2)¶ Bases:
object
-
pyteal.
compileTeal
(ast: pyteal.Expr, mode: pyteal.Mode, *, version: int = 2) → 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.
- version (optional) – The TEAL version used to assemble the program. This will determine which expressions and fields are able to be used in the program and how expressions compile to TEAL opcodes. Defaults to 2 if not included.
Returns: A TEAL assembly program compiled from the input expression.
Raises: TealInputError
– if an operation in ast is not supported by the supplied mode and version.
-
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: str)¶ Bases:
Exception
-
exception
pyteal.
TealCompileError
(msg: str, sourceExpr: Optional[Expr])¶ Bases:
Exception