Transaction Fields and Global Parameters

PyTeal smart contracts can access properties of the current transaction and the state of the blockchain when they are running.

Transaction Fields

Information about the current transaction being evaluated can be obtained using the Txn object. Below are the PyTeal expressions that refer to transaction fields:

Operator Type Notes
Txn.sender() TealType.bytes 32 byte address
Txn.fee() TealType.uint64 in microAlgos
Txn.first_valid() TealType.uint64 round number
Txn.last_valid() TealType.uint64 round number
Txn.note() TealType.bytes transaction note in bytes TealType.bytes transaction lease in bytes
Txn.receiver() TealType.bytes 32 byte address
Txn.amount() TealType.uint64 in microAlgos
Txn.close_remainder_to() TealType.bytes 32 byte address
Txn.vote_pk() TealType.bytes 32 byte address
Txn.selection_pk() TealType.bytes 32 byte address
Txn.vote_first() TealType.uint64  
Txn.vote_last() TealType.uint64  
Txn.vote_key_dilution() TealType.uint64  
Txn.type() TealType.bytes  
Txn.type_enum() TealType.uint64 see table below
Txn.xfer_asset() TealType.uint64 asset ID
Txn.asset_amount() TealType.uint64 value in Asset’s units
Txn.asset_sender() TealType.bytes 32 byte address, causes clawback of all value if sender is the Clawback
Txn.asset_receiver() TealType.bytes 32 byte address
Txn.asset_close_to() TealType.bytes 32 byte address
Txn.group_index() TealType.uint64 position of this transaction within a transaction group
Txn.tx_id() TealType.bytes the computed ID for this transaction, 32 bytes
Txn.application_id() TealType.uint64  
Txn.on_completion() TealType.uint64  
Txn.approval_program() TealType.bytes  
Txn.clear_state_program() TealType.bytes  
Txn.rekey_to() TealType.bytes 32 byte address
Txn.config_asset() TealType.uint64  
Txn.config_asset_total() TealType.uint64  
Txn.config_asset_decimals() TealType.uint64  
Txn.config_asset_default_frozen() TealType.uint64  
Txn.config_asset_unit_name() TealType.bytes  
Txn.config_asset_name() TealType.bytes  
Txn.config_asset_url() TealType.bytes  
Txn.config_asset_metadata_hash() TealType.bytes  
Txn.config_asset_manager() TealType.bytes 32 byte address
Txn.config_asset_reserve() TealType.bytes 32 byte address
Txn.config_asset_freeze() TealType.bytes 32 byte address
Txn.config_asset_clawback() TealType.bytes 32 byte address
Txn.freeze_asset() TealType.uint64  
Txn.freeze_asset_account() TealType.bytes 32 byte address
Txn.freeze_asset_frozen() TealType.uint64  
Txn.application_args() TealType.bytes[]  
Txn.accounts() TealType.bytes[]  

The Txn.type_enum() values can be checked using the TxnType enum:

Value Numerical Value Type String Description
TxnType.Unknown 0 unkown unknown type, invalid
TxnType.Payment 1 pay payment
TxnType.KeyRegistration 2 keyreg key registration
TxnType.AssetConfig 3 acfg asset config
TxnType.AssetTransfer 4 axfer asset transfer
TxnType.AssetFreeze 5 afrz asset freeze
TxnType.ApplicationCall 6 appl application call

Atomic Tranfers

Atomic Transfers are irreducible batch transactions that allow groups of transactions to be submitted at one time. If any of the transactions fail, then all the transactions will fail. PyTeal allows programs to access information about the transactions in an atomic transfer group using the Gtxn object. This object acts like a list of TxnObject, meaning all of the above transaction fields on Txn are available on the elements of Gtxn. For example:

Gtxn[0].sender() # get the sender of the first transaction in the atomic transfer group
Gtxn[1].receiver() # get the receiver of the second transaction in the atomic transfer group

Gtxn is zero-indexed and the maximum size of an atomic transfer group is 16.

Global Parameters

Information about the current state of the blockchain can be obtained using the following Global expressions:

Operator Type Notes
Global.min_txn_fee() TealType.uint64 in microAlgos
Global.min_balance() TealType.uint64 in mircoAlgos
Global.max_txn_life() TealType.uint64 number of rounds
Global.zero_address() TealType.bytes 32 byte address of all zero bytes
Global.group_size() TealType.uint64 number of txns in this atomic transaction group, At least 1
Global.logic_sig_version() TealType.uint64 the maximum supported TEAL version
Global.round() TealType.uint64 the current round number
Global.latest_timestamp() TealType.uint64 the latest confirmed block UNIX timestamp
Global.current_application_id() TealType.uint64 the ID of the current application executing