Standard Library¶
In addition to the AVM opcodes Tealish provides some builtin utility functions. All builtin Tealish functions are Capitalized to distinguish them from the AVM functions which are lowercase.
- Cast(Expression, Type) any¶
Tells the compiler to treat the expression as the given type. The compiler adds a runtime type length assertion.
bytes[32] address = Cast(Txn.ApplicationArgs[0], bytes[32])
- UncheckedCast(Expression, Type) any¶
Tells the compiler to treat the expression as the given type. The compiler does not add any runtime type length assertion.
bytes[32] address = UncheckedCast(Txn.ApplicationArgs[0], bytes[32])
- Concat(bytes, bytes, ...) bytes¶
Concatenates multiple byte strings together.
bytes foo = Concat(a, b, c, d)
- Rpad(bytes, len) bytes¶
Pads the byte string with 0 bytes (”\x00”) to the right.
bytes[10] b = Rpad("abc", 10) assert(b == "abc\x00\x00\x00\x00\x00\x00\x00")
- Lpad(bytes, len) bytes¶
Pads the byte string with 0 bytes (”\x00”) to the left.
bytes[10] b = Lpad("abc", 10) assert(b == "\x00\x00\x00\x00\x00\x00\x00abc")
- SizeOf(Struct) int¶
Returns the size of a
structtype as a compile time constant.Item item1 = bzero(SizeOf(Item))
- Address(address) bytes¶
Supports hardcoding of address constants in contracts in the standard Algorand base32 format. Note: the address must be a constant at compile time.
const TINYMAN = Address("RIKLQ5HEVXAOAWYSW2LGQFYGWVO4J6LIAQQ72ZRULHZ4KS5NRPCCKYPCUU")
- ARC28Event(signature, bytes, ...) bytes¶
Generates an ARC28 compliant byte string for logging event messages. The message is prefixed with the first 4 bytes of the SHA512_256 hash of the signature.
log(ARC28Event("set_manager(address)", new_manager)) # The above line generates the following Teal: pushbytes 0xba87e7f4 // SHA512_256("set_manager(address)")[:4] load 4 // new_manager concat log