Data Types and ConstantsΒΆ
A PyTeal expression has one of the following two data types:
TealType.uint64
, 64 bit unsigned integerTealType.bytes
, a slice of bytes
For example, all the transaction arguments (e.g. Arg(0)
) are of type TealType.bytes
.
The first valid round of current transaction (Txn.first_valid()
) is typed TealType.uint64
.
Int(n)
creates a TealType.uint64
constant, where n >= 0 and n < 2 ** 64
.
Bytes(encoding, value)
creates a TealType.bytes
constant, where encoding
could be either
of the following:
"base16"
: its pairedvalue
needs to be a RFC 4648 base16 encoded string, e.g."0xA21212EF"
or"A21212EF"
"base32"
: its pairedvalue
needs to be a RFC 4648 base32 encoded string without padding, e.g."7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M"
"base64"
: its pairedvalue
needs to be a RFC 4648 base64 encoded string, e.g."Zm9vYmE="
All PyTeal expressions are type checked at construction time, for example, running
the following code triggers a TealTypeError
:
Int(0) < Arg(0)
Since <
(overloaded Python operator, see Arithmetic Operators for more details)
requires both operands of type TealType.uint64
,
while Arg(0)
is of type TealType.bytes
.
Converting a value to its corresponding value in the other data type is supported by the following two operators:
Itob(n)
: generate aTealType.bytes
value from aTealType.uint64
valuen
Btoi(b)
: generate aTealType.uint64
value from aTealType.bytes
valueb