AVM Reference¶
This page provides a guide to the fields and functions (opcodes) of the Algorand Virtual Machine. Please refer to the official AVM docs for further details.
The content of this page is mostly autogenerated from the Teal language specification.
Fields¶
Transaction Fields¶
This section lists all Fields available on transactions. They can be accessed from Txn, Gtxn[i], Itxn as described in Fields.
Txn.Accounts
Txn.Amount
Txn.ApplicationArgs
Txn.ApplicationID
Txn.Applications
Txn.ApprovalProgram
Txn.ApprovalProgramPages
Txn.AssetAmount
Txn.AssetCloseTo
Txn.AssetReceiver
Txn.AssetSender
Txn.Assets
Txn.ClearStateProgram
Txn.ClearStateProgramPages
Txn.CloseRemainderTo
Txn.ConfigAsset
Txn.ConfigAssetClawback
Txn.ConfigAssetDecimals
Txn.ConfigAssetDefaultFrozen
Txn.ConfigAssetFreeze
Txn.ConfigAssetManager
Txn.ConfigAssetMetadataHash
Txn.ConfigAssetName
Txn.ConfigAssetReserve
Txn.ConfigAssetTotal
Txn.ConfigAssetURL
Txn.ConfigAssetUnitName
Txn.CreatedApplicationID
Txn.CreatedAssetID
Txn.ExtraProgramPages
Txn.Fee
Txn.FirstValid
Txn.FirstValidTime
Txn.FreezeAsset
Txn.FreezeAssetAccount
Txn.FreezeAssetFrozen
Txn.GlobalNumByteSlice
Txn.GlobalNumUint
Txn.GroupIndex
Txn.LastLog
Txn.LastValid
Txn.Lease
Txn.LocalNumByteSlice
Txn.LocalNumUint
Txn.Logs
Txn.Nonparticipation
Txn.Note
Txn.NumAccounts
Txn.NumAppArgs
Txn.NumApplications
Txn.NumApprovalProgramPages
Txn.NumAssets
Txn.NumClearStateProgramPages
Txn.NumLogs
Txn.OnCompletion
Txn.Receiver
Txn.RekeyTo
Txn.SelectionPK
Txn.Sender
Txn.StateProofPK
Txn.TxID
Txn.Type
Txn.TypeEnum
Txn.VoteFirst
Txn.VoteKeyDilution
Txn.VoteLast
Txn.VotePK
Txn.XferAsset
Global Fields¶
This section lists all Fields available in the Global
namespace.
Global.CallerApplicationAddress
Global.CallerApplicationID
Global.CreatorAddress
Global.CurrentApplicationAddress
Global.CurrentApplicationID
Global.GroupID
Global.GroupSize
Global.LatestTimestamp
Global.LogicSigVersion
Global.MaxTxnLife
Global.MinBalance
Global.MinTxnFee
Global.OpcodeBudget
Global.Round
Global.ZeroAddress
Functions¶
This section lists all opcodes available in the AVM and usable in Tealish in a function calling style. Some AVM opcodes are excluded from this list because they don’t make sense in the context of Tealish or an alternative interface is provided. These are documented below.
- acct_params_get(F: field, A: any) int, any ¶
X is field F from account A. Y is 1 if A owns positive algos, else 0
Fields:
AcctBalance, AcctMinBalance, AcctAuthAddr, AcctTotalNumUint, AcctTotalNumByteSlice, AcctTotalExtraAppPages, AcctTotalAppsCreated, AcctTotalAppsOptedIn, AcctTotalAssetsCreated, AcctTotalAssets, AcctTotalBoxes, AcctTotalBoxBytes
- addw(A: int, B: int) int, int ¶
A plus B as a 128-bit result. X is the carry-bit, Y is the low-order 64 bits.
- app_global_del(A: bytes)¶
delete key A from the global state of the current application
- app_global_get(A: bytes) any ¶
global state of the key A in the current application
- app_global_get_ex(A: int, B: bytes) int, any ¶
X is the global state of application A, key B. Y is 1 if key existed, else 0
- app_global_put(A: bytes, B: any)¶
write B to key A in the global state of the current application
- app_local_del(A: any, B: bytes)¶
delete key B from account A’s local state of the current application
- app_local_get(A: any, B: bytes) any ¶
local state of the key B in the current application in account A
- app_local_get_ex(A: any, B: int, C: bytes) int, any ¶
X is the local state of application B, key C in account A. Y is 1 if key existed, else 0
- app_local_put(A: any, B: bytes, C: any)¶
write C to key B in account A’s local state of the current application
- app_opted_in(A: any, B: int) int ¶
1 if account A is opted in to application B, else 0
- app_params_get(F: field, A: int) int, any ¶
X is field F from app A. Y is 1 if A exists, else 0
Fields:
AppApprovalProgram, AppClearStateProgram, AppGlobalNumUint, AppGlobalNumByteSlice, AppLocalNumUint, AppLocalNumByteSlice, AppExtraProgramPages, AppCreator, AppAddress
- arg(i: int) bytes ¶
Nth LogicSig argument
- args(A: int) bytes ¶
Ath LogicSig argument
- assert(A: int)¶
immediately fail unless A is a non-zero number
- asset_holding_get(F: field, A: any, B: int) int, any ¶
X is field F from account A’s holding of asset B. Y is 1 if A is opted into B, else 0
Fields:
AssetBalance, AssetFrozen
- asset_params_get(F: field, A: int) int, any ¶
X is field F from asset A. Y is 1 if A exists, else 0
Fields:
AssetTotal, AssetDecimals, AssetDefaultFrozen, AssetUnitName, AssetName, AssetURL, AssetMetadataHash, AssetManager, AssetReserve, AssetFreeze, AssetClawback, AssetCreator
- balance(A: any) int ¶
balance for account A, in microalgos. The balance is observed after the effects of previous transactions in the group, and after the fee for the current transaction is deducted. Changes caused by inner transactions are observable immediately following itxn_submit
- base64_decode(i: int, A: bytes) bytes ¶
decode A which was base64-encoded using _encoding_ E. Fail if A is not base64 encoded with encoding E
- bitlen(A: any) int ¶
The highest set bit in A. If A is a byte-array, it is interpreted as a big-endian unsigned integer. bitlen of 0 is 0, bitlen of 8 is 4
- block(i: int, A: int) any ¶
field F of block A. Fail unless A falls between txn.LastValid-1002 and txn.FirstValid (exclusive)
- box_create(A: bytes, B: int) int ¶
create a box named A, of length B. Fail if A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1
- box_del(A: bytes) int ¶
delete box named A if it exists. Return 1 if A existed, 0 otherwise
- box_extract(A: bytes, B: int, C: int) bytes ¶
read C bytes from box A, starting at offset B. Fail if A does not exist, or the byte range is outside A’s size.
- box_get(A: bytes) int, bytes ¶
X is the contents of box A if A exists, else ‘’. Y is 1 if A exists, else 0.
- box_len(A: bytes) int, int ¶
X is the length of box A if A exists, else 0. Y is 1 if A exists, else 0.
- box_put(A: bytes, B: bytes)¶
replaces the contents of box A with byte-array B. Fails if A exists and len(B) != len(box A). Creates A if it does not exist
- box_replace(A: bytes, B: int, C: bytes)¶
write byte-array C into box A, starting at offset B. Fail if A does not exist, or the byte range is outside A’s size.
- bsqrt(A: bytes) bytes ¶
The largest integer I such that I^2 <= A. A and I are interpreted as big-endian unsigned integers
- btoi(A: bytes) int ¶
converts big-endian byte array A to uint64. Fails if len(A) > 8. Padded by leading 0s if len(A) < 8.
- bury(i: int, A: any)¶
replace the Nth value from the top of the stack with A. bury 0 fails.
- bzero(A: int) bytes ¶
zero filled byte-array of length A
- concat(A: bytes, B: bytes) bytes ¶
join A and B
- cover(i: int, A: any) any ¶
remove top of stack, and place it deeper in the stack such that N elements are above it. Fails if stack depth <= N.
- dig(i: int, A: any) any, any ¶
Nth value from the top of the stack. dig 0 is equivalent to dup
- divmodw(A: int, B: int, C: int, D: int) int, int, int, int ¶
W,X = (A,B / C,D); Y,Z = (A,B modulo C,D)
- divw(A: int, B: int, C: int) int ¶
A,B / C. Fail if C == 0 or if result overflows.
- dup(A: any) any, any ¶
duplicate A
- dup2(A: any, B: any) any, any, any, any ¶
duplicate A and B
- dupn(i: int, A: any)¶
duplicate A, N times
- ecdsa_pk_decompress(i: int, A: bytes) bytes, bytes ¶
decompress pubkey A into components X, Y
- ecdsa_pk_recover(i: int, A: bytes, B: int, C: bytes, D: bytes) bytes, bytes ¶
for (data A, recovery id B, signature C, D) recover a public key
- ecdsa_verify(i: int, A: bytes, B: bytes, C: bytes, D: bytes, E: bytes) int ¶
for (data A, signature B, C and pubkey D, E) verify the signature of the data against the pubkey => {0 or 1}
- ed25519verify(A: bytes, B: bytes, C: bytes) int ¶
for (data A, signature B, pubkey C) verify the signature of (“ProgData” || program_hash || data) against the pubkey => {0 or 1}
- ed25519verify_bare(A: bytes, B: bytes, C: bytes) int ¶
for (data A, signature B, pubkey C) verify the signature of the data against the pubkey => {0 or 1}
- exp(A: int, B: int) int ¶
A raised to the Bth power. Fail if A == B == 0 and on overflow
- expw(A: int, B: int) int, int ¶
A raised to the Bth power as a 128-bit result in two uint64s. X is the high 64 bits, Y is the low. Fail if A == B == 0 or if the results exceeds 2^128-1
- extract(i: int, i: int, A: bytes) -> bytes
A range of bytes from A starting at S up to but not including S+L. If L is 0, then extract to the end of the string. If S or S+L is larger than the array length, the program fails
- extract3(A: bytes, B: int, C: int) bytes ¶
A range of bytes from A starting at B up to but not including B+C. If B+C is larger than the array length, the program fails extract3 can be called using extract with no immediates.
- extract_uint16(A: bytes, B: int) int ¶
A uint16 formed from a range of big-endian bytes from A starting at B up to but not including B+2. If B+2 is larger than the array length, the program fails
- extract_uint32(A: bytes, B: int) int ¶
A uint32 formed from a range of big-endian bytes from A starting at B up to but not including B+4. If B+4 is larger than the array length, the program fails
- extract_uint64(A: bytes, B: int) int ¶
A uint64 formed from a range of big-endian bytes from A starting at B up to but not including B+8. If B+8 is larger than the array length, the program fails
- frame_bury(i: int, A: any)¶
replace the Nth (signed) value from the frame pointer in the stack with A
- frame_dig(i: int) any ¶
Nth (signed) value from the frame pointer.
- gaid(i: int) int ¶
ID of the asset or application created in the Tth transaction of the current group
- gaids(A: int) int ¶
ID of the asset or application created in the Ath transaction of the current group
- getbit(A: any, B: int) int ¶
Bth bit of (byte-array or integer) A. If B is greater than or equal to the bit length of the value (8*byte length), the program fails
- getbyte(A: bytes, B: int) int ¶
Bth byte of A, as an integer. If B is greater than or equal to the array length, the program fails
- gitxn(F: field) any ¶
field F of the Tth transaction in the last inner group submitted
Fields:
Sender, Fee, FirstValid, FirstValidTime, LastValid, Note, Lease, Receiver, Amount, CloseRemainderTo, VotePK, SelectionPK, VoteFirst, VoteLast, VoteKeyDilution, Type, TypeEnum, XferAsset, AssetAmount, AssetSender, AssetReceiver, AssetCloseTo, GroupIndex, TxID, ApplicationID, OnCompletion, ApplicationArgs, NumAppArgs, Accounts, NumAccounts, ApprovalProgram, ClearStateProgram, RekeyTo, ConfigAsset, ConfigAssetTotal, ConfigAssetDecimals, ConfigAssetDefaultFrozen, ConfigAssetUnitName, ConfigAssetName, ConfigAssetURL, ConfigAssetMetadataHash, ConfigAssetManager, ConfigAssetReserve, ConfigAssetFreeze, ConfigAssetClawback, FreezeAsset, FreezeAssetAccount, FreezeAssetFrozen, Assets, NumAssets, Applications, NumApplications, GlobalNumUint, GlobalNumByteSlice, LocalNumUint, LocalNumByteSlice, ExtraProgramPages, Nonparticipation, Logs, NumLogs, CreatedAssetID, CreatedApplicationID, LastLog, StateProofPK, ApprovalProgramPages, NumApprovalProgramPages, ClearStateProgramPages, NumClearStateProgramPages
- gitxna(F: field) any ¶
Ith value of the array field F from the Tth transaction in the last inner group submitted
Fields:
ApplicationArgs, Accounts, Assets, Applications, Logs, ApprovalProgramPages, ClearStateProgramPages
- gitxnas(i: int, i: int, A: int) -> any
Ath value of the array field F from the Tth transaction in the last inner group submitted
- gload(i: int, i: int) -> any
Ith scratch space value of the Tth transaction in the current group
- gloads(i: int, A: int) any ¶
Ith scratch space value of the Ath transaction in the current group
- gloadss(A: int, B: int) any ¶
Bth scratch space value of the Ath transaction in the current group
- global(F: field) any ¶
global field F
Fields:
MinTxnFee, MinBalance, MaxTxnLife, ZeroAddress, GroupSize, LogicSigVersion, Round, LatestTimestamp, CurrentApplicationID, CreatorAddress, CurrentApplicationAddress, GroupID, OpcodeBudget, CallerApplicationID, CallerApplicationAddress
- itob(A: int) bytes ¶
converts uint64 A to big-endian byte array, always of length 8
- itxn(F: field) any ¶
field F of the last inner transaction
Fields:
Sender, Fee, FirstValid, FirstValidTime, LastValid, Note, Lease, Receiver, Amount, CloseRemainderTo, VotePK, SelectionPK, VoteFirst, VoteLast, VoteKeyDilution, Type, TypeEnum, XferAsset, AssetAmount, AssetSender, AssetReceiver, AssetCloseTo, GroupIndex, TxID, ApplicationID, OnCompletion, ApplicationArgs, NumAppArgs, Accounts, NumAccounts, ApprovalProgram, ClearStateProgram, RekeyTo, ConfigAsset, ConfigAssetTotal, ConfigAssetDecimals, ConfigAssetDefaultFrozen, ConfigAssetUnitName, ConfigAssetName, ConfigAssetURL, ConfigAssetMetadataHash, ConfigAssetManager, ConfigAssetReserve, ConfigAssetFreeze, ConfigAssetClawback, FreezeAsset, FreezeAssetAccount, FreezeAssetFrozen, Assets, NumAssets, Applications, NumApplications, GlobalNumUint, GlobalNumByteSlice, LocalNumUint, LocalNumByteSlice, ExtraProgramPages, Nonparticipation, Logs, NumLogs, CreatedAssetID, CreatedApplicationID, LastLog, StateProofPK, ApprovalProgramPages, NumApprovalProgramPages, ClearStateProgramPages, NumClearStateProgramPages
- itxna(F: field) any ¶
Ith value of the array field F of the last inner transaction
Fields:
ApplicationArgs, Accounts, Assets, Applications, Logs, ApprovalProgramPages, ClearStateProgramPages
- itxnas(i: int, A: int) any ¶
Ath value of the array field F of the last inner transaction
- json_ref(i: int, A: bytes, B: bytes) any ¶
key B’s value, of type R, from a [valid](jsonspec.md) utf-8 encoded json object A
- keccak256(A: bytes) bytes ¶
Keccak256 hash of value A, yields [32]byte
- len(A: bytes) int ¶
yields length of byte value A
- load(i: int) any ¶
Ith scratch space value. All scratch spaces are 0 at program start.
- loads(A: int) any ¶
Ath scratch space value. All scratch spaces are 0 at program start.
- log(A: bytes)¶
write A to log state of the current application
- match()¶
given match cases from A[1] to A[N], branch to the Ith label where A[I] = B. Continue to the following instruction if no matches are found.
- method(i: int) bytes ¶
- min_balance(A: any) int ¶
minimum required balance for account A, in microalgos. Required balance is affected by ASA, App, and Box usage. When creating or opting into an app, the minimum balance grows before the app code runs, therefore the increase is visible there. When deleting or closing out, the minimum balance decreases after the app executes. Changes caused by inner transactions or box usage are observable immediately following the opcode effecting the change.
- mulw(A: int, B: int) int, int ¶
A times B as a 128-bit result in two uint64s. X is the high 64 bits, Y is the low
- pop(A: any)¶
discard A
- popn(i: int)¶
remove N values from the top of the stack
- proto(i: int, i: int)
Prepare top call frame for a retsub that will assume A args and R return values.
- pushbytes() bytes ¶
immediate BYTES
- pushbytess()¶
push sequences of immediate byte arrays to stack (first byte array being deepest)
- pushint() int ¶
immediate UINT
- pushints()¶
push sequence of immediate uints to stack in the order they appear (first uint being deepest)
- replace2(i: int, A: bytes, B: bytes) bytes ¶
Copy of A with the bytes starting at S replaced by the bytes of B. Fails if S+len(B) exceeds len(A) replace2 can be called using replace with 1 immediate.
- replace3(A: bytes, B: int, C: bytes) bytes ¶
Copy of A with the bytes starting at B replaced by the bytes of C. Fails if B+len(C) exceeds len(A) replace3 can be called using replace with no immediates.
- select(A: any, B: any, C: int) any ¶
selects one of two values based on top-of-stack: B if C != 0, else A
- setbit(A: any, B: int, C: int) any ¶
Copy of (byte-array or integer) A, with the Bth bit set to (0 or 1) C. If B is greater than or equal to the bit length of the value (8*byte length), the program fails
- setbyte(A: bytes, B: int, C: int) bytes ¶
Copy of A with the Bth byte set to small integer (between 0..255) C. If B is greater than or equal to the array length, the program fails
- sha256(A: bytes) bytes ¶
SHA256 hash of value A, yields [32]byte
- sha3_256(A: bytes) bytes ¶
SHA3_256 hash of value A, yields [32]byte
- sha512_256(A: bytes) bytes ¶
SHA512_256 hash of value A, yields [32]byte
- shl(A: int, B: int) int ¶
A times 2^B, modulo 2^64
- shr(A: int, B: int) int ¶
A divided by 2^B
- sqrt(A: int) int ¶
The largest integer I such that I^2 <= A
- store(i: int, A: any)¶
store A to the Ith scratch space
- stores(A: int, B: any)¶
store B to the Ath scratch space
- substring(i: int, i: int, A: bytes) -> bytes
A range of bytes from A starting at S up to but not including E. If E < S, or either is larger than the array length, the program fails
- substring3(A: bytes, B: int, C: int) bytes ¶
A range of bytes from A starting at B up to but not including C. If C < B, or either is larger than the array length, the program fails
- swap(A: any, B: any) any, any ¶
swaps A and B on stack
- switch(A: int)¶
branch to the Ath label. Continue at following instruction if index A exceeds the number of labels.
- uncover(i: int, A: any) any ¶
remove the value at depth N in the stack and shift above items down so the Nth deep value is on top of the stack. Fails if stack depth <= N.
- vrf_verify(i: int, A: bytes, B: bytes, C: bytes) int, bytes ¶
Verify the proof B of message A against pubkey C. Returns vrf output and verification flag.
Operators¶
This section lists all AVM operator opcodes that can be used in math/logic expressions in Tealish.
A + B
A plus B. Fail on overflow.
A - B
A minus B. Fail if B > A.
A * B
A times B. Fail on overflow.
A / B
A divided by B (truncated division). Fail if B == 0.
A % B
A modulo B. Fail if B == 0.
A == B
A is equal to B => {0 or 1}
A >= B
A greater than or equal to B => {0 or 1}
A <= B
A less than or equal to B => {0 or 1}
A > B
A greater than B => {0 or 1}
A < B
A less than B => {0 or 1}
A != B
A is not equal to B => {0 or 1}
A && B
A is not zero and B is not zero => {0 or 1}
A || B
A is not zero or B is not zero => {0 or 1}
A | B
A bitwise-or B
A % B
A modulo B. Fail if B == 0.
A ^ B
A bitwise-xor B
!A
A == 0 yields 1; else 0
A & B
A bitwise-and B
~A
bitwise invert value A
A b+ B
A plus B. A and B are interpreted as big-endian unsigned integers
A b- B
A minus B. A and B are interpreted as big-endian unsigned integers. Fail on underflow.
A b/ B
A divided by B (truncated division). A and B are interpreted as big-endian unsigned integers. Fail if B is zero.
A b* B
A times B. A and B are interpreted as big-endian unsigned integers.
A b% B
A modulo B. A and B are interpreted as big-endian unsigned integers. Fail if B is zero.
A b== B
1 if A is equal to B, else 0. A and B are interpreted as big-endian unsigned integers
A b!= B
0 if A is equal to B, else 1. A and B are interpreted as big-endian unsigned integers
A b>= B
1 if A is greater than or equal to B, else 0. A and B are interpreted as big-endian unsigned integers
A b<= B
1 if A is less than or equal to B, else 0. A and B are interpreted as big-endian unsigned integers
A b> B
1 if A is greater than B, else 0. A and B are interpreted as big-endian unsigned integers
A b< B
1 if A is less than B, else 0. A and B are interpreted as big-endian unsigned integers
A b| B
A bitwise-or B. A and B are zero-left extended to the greater of their lengths
A b& B
A bitwise-and B. A and B are zero-left extended to the greater of their lengths
A b^ B
A bitwise-xor B. A and B are zero-left extended to the greater of their lengths
b~A
A with all bits inverted
Unsupported Opcodes¶
Some opcodes are excluded from the above lists because they don’t make sense in the context of Tealish or an alternative interface is provided:
global, txn, txna, txnas, gtxn, gtxna, gtxns, gtxnsas
The Fields syntax is encouraged instead of the function style.
itxn_begin, itxn_next, itxn_submit
The Tealish
inner_txn
construct is encouraged instead.callsub, retsub
Tealish
Functions
are used instead.b, bz, bnz, match, switch
Tealish
If/Else
,Loops
orswitch
are used instead. Tealish does not support labels so these opcodes cannot be used.return
exit
is an alias ofreturn
in Tealish and its use is encouraged to avoid confusion withreturn
in Tealish functions.intc, bytec
Tealish does not expose the int/bytes constants block and to Tealish code.