$$ \newcommand \App {\mathrm{App}} \newcommand \MaxAppTotalTxnReferences {\App_{r,\max}} \newcommand \MaxExtraAppProgramPages {\App_{\mathrm{page},\max}} \newcommand \MaxAppProgramLen {\App_{\mathrm{prog},\max}} \newcommand \MaxGlobalSchemaEntries {\App_{\mathrm{GS},\max}} \newcommand \MaxLocalSchemaEntries {\App_{\mathrm{LS},\max}} \newcommand \MaxAppArgs {\App_{\mathrm{arg},\max}} \newcommand \MaxAppTotalArgLen {\App_{\mathrm{ay},\max}} \newcommand \MaxAppTxnAccounts {\App_{\mathrm{acc},\max}} \newcommand \MaxAppTxnForeignApps {\App_{\mathrm{app},\max}} \newcommand \MaxAppTxnForeignAssets {\App_{\mathrm{asa},\max}} \newcommand \Box {\mathrm{Box}} \newcommand \MaxAppBoxReferences {\App_{\Box,\max}} \newcommand \MaxAppKeyLen {\App_{\mathrm{k},\max}} $$

Application Call Transaction

Fields

An application call transaction additionally has the following fields:

FIELDCODECTYPEREQUIRED
Application IDapiduint64Yes (except for Creation)
On Completion Actionapanuint64Yes
Approval Programapap[]byteNo
Clear State Programapsu[]byteNo
Extra Program Pagesapepuint64No
Global State SchemaapgsstructNo
Local State SchemaaplsstructNo
Argumentsapaa[][]byteNo
Foreign Accountsapat[]addressNo
Foreign Applicationsapfa[]uint64No
Foreign Assetsapas[]uint64No
Box Referencesapbx[]structNo

The sum of the number of foreign accounts in apat, foreign application in apfa, foreign asset in apas, and box references in apbx MUST NOT exceed \( \MaxAppTotalTxnReferences \).

Application ID

The application ID identifies the application being called.

If the application ID is omitted (zero), this transaction is creating an application.

On Completion Action

The on completion action specifies an additional effect of this transaction on the application’s state in the sender or application creator’s account data.

The apan field values are enumerated as follows:

ACTIONVALUEEFFECT
NoOpOC0Only execute the Approval Program associated with this application ID, with no additional effects.
OptInOC1Before executing the Approval Program, allocate local state for this application ID into the sender’s account data.
CloseOutOC2After executing the Approval Program, clear any local state for this application ID out of the sender’s account data.
ClearStateOC3Do not execute the Approval Program, and instead execute the Clear State Program (which may not reject this transaction). Additionally, clear any local state for this application ID out of the sender’s account data (as in CloseOutOC).
UpdateApplicationOC4After executing the Approval Program, replace the Approval Program and Clear State Program associated with this application ID with the programs specified in this transaction.
DeleteApplicationOC5After executing the Approval Program, delete the parameters of with this application ID from the account data of the application’s creator.

Approval Program

The approval program (OPTIONAL) contains the approval program bytecode.

This field is used for application creation and updates, and sets the corresponding application’s Approval Program.

Clear State Program

The clear state program (OPTIONAL) contains the clear state program bytecode.

This field is used for application creation and updates, and sets the corresponding application’s Clear State Program.

  • The Approval Program and the Clear State Program MUST have the same version number if either is \( 6 \) or higher.

Extra Program Pages

A program page (OPTIONAL) is a chunk of application program bytecode. The extra program pages define the number of program pages besides the first one.

This field is only used during application creation, and requests an increased maximum size for the Approval Program or Clear State Program.

  • There MUST NOT be more than \( \MaxExtraAppProgramPages \) extra program pages,

  • The program page byte length MUST NOT exceed \( \MaxAppProgramLen \).

Global State Schema

The global state schema (OPTIONAL) defines the global state allocated into the creator account that of the application ID.

The global state schema is a structure containing:

FIELDCODECTYPEDESCRIPTION
Number of Uintsnuiuint64The number of global 64-bit unsigned integer variables for the application.
Number of Bytesnbsuint64The number of global byte-array variables for the application.

This field is only used during application creation, and sets bounds on the size of the global state associated with this application.

  • There MUST NOT be more than \( \MaxGlobalSchemaEntries \) global variables for the application.

TODO: Restrictions on key-value lengths

Local State Schema

The local state schema (OPTIONAL) defines the local state allocated into the accounts that opt-in the application ID.

The local state schema is a structure containing:

FIELDCODECTYPEDESCRIPTION
Number of Uintsnuiuint64The number of local 64-bit unsigned integer variables for the application.
Number of Bytesnbsuint64The number of local byte-array variables for the application.

This field is only used during application creation, and sets bounds on the size of the local state for accounts that opt in to this application.

  • There MUST NOT be more than \( \MaxLocalSchemaEntries \) local variables for the application.

TODO: Restrictions on key-value lengths

Arguments

The application arguments (OPTIONAL) list provides byte-array arguments to the application being called.

  • There MUST NOT be more than \( \MaxAppArgs \) entries in this list,

  • The sum of their byte lengths MUST NOT exceed \( \MaxAppTotalArgLen \).

Foreign Accounts

The foreign accounts (OPTIONAL) list specifies the accounts, besides the sender, whose local states MAY be referred to by executing the Approval Program or the Clear State Program. These accounts are referred to by their 32-byte addresses.

  • There MUST NOT be more than \( \MaxAppTxnAccounts \) entries in this list.

Foreign Applications

The foreign applications (OPTIONAL) list specifies the application IDs, besides the application whose Approval Program or Clear State Program is executing, that the executing program MAY read global state from. These applications are referred to by their 64-bit unsigned integer IDs.

  • There MUST NOT be more than \( \MaxAppTxnForeignApps \) entries in this list.

Foreign Assets

The foreign assets (OPTIONAL) list specifies the asset IDs from which the executing Approval Program or Clear State Program MAY read asset parameters. These assets are referred to by their 64-bit unsigned integer IDs.

  • There MUST NOT be more than \( \MaxAppTxnForeignAssets \) entries in this list.

Box References

The box references (OPTIONAL) list specifies the boxes that the executing Approval Program, or any other Approval Program in the same group, MAY access for reading or writing when the box reference matches the running program application IDs.

The box is a structure containing:

FIELDCODECTYPEDESCRIPTION
Indexiuint64A \( 1 \)-based index in the foreign applications (apfa) list.
Namen[]byteThe box identifier.

A \( 0 \) index (i) is interpreted as the application ID of this transaction (apid, or the ID allocated for the created application when apid is \( 0 \)).

  • There MUST NOT be more than \( \MaxAppBoxReferences \) entries in this list.

  • The box name byte length MUST NOT exceed \( \MaxAppKeyLen \).

Validation

TODO

Semantic

TODO