algopy.arc4

Module Contents

Classes

ARC4Client

ARC4Contract

A contract that conforms to the ARC4 ABI specification, functions decorated with @abimethod or @baremethod will form the public interface of the contract

Address

An alias for an array containing 32 bytes representing an Algorand address

BigUFixedNxM

An ARC4 UFixed representing a decimal with the number of bits and precision specified.

BigUIntN

An ARC4 UInt consisting of the number of bits specified.

Bool

An ARC4 encoded bool

Byte

An ARC4 alias for a UInt8

DynamicArray

A dynamically sized ARC4 Array of the specified type

DynamicBytes

A variable sized array of bytes

StaticArray

A fixed length ARC4 Array of the specified type and length

String

An ARC4 sequence of bytes containing a UTF8 string

Struct

Base class for ARC4 Struct types

Tuple

An ARC4 ABI tuple, containing other ARC4 ABI types

UFixedNxM

An ARC4 UFixed representing a decimal with the number of bits and precision specified.

UIntN

An ARC4 UInt consisting of the number of bits specified.

Functions

abimethod

Decorator that indicates a method is an ARC4 ABI method.

arc4_signature

Returns the ARC4 encoded method selector for the specified signature

baremethod

Decorator that indicates a method is an ARC4 bare method.

emit

Emit an ARC-28 event for the provided event signature or name, and provided args.

Data

UInt128

An ARC4 UInt128

UInt16

An ARC4 UInt16

UInt256

An ARC4 UInt256

UInt32

An ARC4 UInt32

UInt512

An ARC4 UInt512

UInt64

An ARC4 UInt64

UInt8

An ARC4 UInt8

abi_call

Provides a typesafe way of calling ARC4 methods via an inner transaction

API

class algopy.arc4.ARC4Client
class algopy.arc4.ARC4Contract

A contract that conforms to the ARC4 ABI specification, functions decorated with @abimethod or @baremethod will form the public interface of the contract

The approval_program will be implemented by the compiler, and route application args according to the ARC4 ABI specification

The clear_state_program will by default return True, but can be overridden

class algopy.arc4.Address(value: algopy.Account | str | algopy.Bytes = ..., /)

An alias for an array containing 32 bytes representing an Algorand address

Initialization

If value is a string, it should be a 58 character base32 string, ie a base32 string-encoded 32 bytes public key + 4 bytes checksum. If value is a Bytes, it’s length checked to be 32 bytes - to avoid this check, use Address.from_bytes(...) instead. Defaults to the zero-address.

__bool__() bool

Returns True if not equal to the zero address

__eq__(other: algopy.arc4.Address | algopy.Account | str) bool

Address equality is determined by the address of another arc4.Address, Account or str

__iter__() Iterator[algopy.arc4._TArrayItem]
__ne__(other: algopy.arc4.Address | algopy.Account | str) bool

Address equality is determined by the address of another arc4.Address, Account or str

__reversed__() Iterator[algopy.arc4._TArrayItem]
classmethod __subclasshook__(C)
copy() Self
classmethod from_log(log: algopy.Bytes, /) Self
property length: algopy.UInt64
property native: algopy.Account

Return the Account representation of the address after ARC4 decoding

class algopy.arc4.BigUFixedNxM(value: str = '0.0', /)

An ARC4 UFixed representing a decimal with the number of bits and precision specified.

Max size: 512 bits

Initialization

Construct an instance of UFixedNxM where value (v) is determined from the original decimal value (d) by the formula v = round(d * (10^M))

__bool__() bool

Returns True if not equal to zero

classmethod from_log(log: algopy.Bytes, /) Self
class algopy.arc4.BigUIntN(value: algopy.BigUInt | algopy.UInt64 | int = 0, /)

An ARC4 UInt consisting of the number of bits specified.

Max size: 512 bits

Initialization

__bool__() bool
__eq__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__ge__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__gt__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__le__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__lt__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__ne__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
classmethod from_log(log: algopy.Bytes, /) Self
property native: algopy.BigUInt

Return the BigUInt representation of the value after ARC4 decoding

class algopy.arc4.Bool(value: bool = False, /)

An ARC4 encoded bool

Initialization

classmethod from_log(log: algopy.Bytes, /) Self
property native: bool

Return the bool representation of the value after ARC4 decoding

class algopy.arc4.Byte(value: algopy.BigUInt | algopy.UInt64 | int = 0, /)

An ARC4 alias for a UInt8

Initialization

__bool__() bool
__eq__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__ge__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__gt__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__le__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__lt__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__ne__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
classmethod from_log(log: algopy.Bytes, /) Self
property native: algopy.UInt64
class algopy.arc4.DynamicArray(*items: algopy.arc4._TArrayItem)

A dynamically sized ARC4 Array of the specified type

Initialization

__bool__() bool

Returns True if not an empty array

__iter__() Iterator[algopy.arc4._TArrayItem]

Returns an iterator for the items in the array

__reversed__() Iterator[algopy.arc4._TArrayItem]

Returns an iterator for the items in the array, in reverse order

classmethod __subclasshook__(C)
append(item: algopy.arc4._TArrayItem, /) None

Append items to this array

copy() Self

Create a copy of this array

extend(other: collections.abc.Iterable[algopy.arc4._TArrayItem], /) None

Extend this array with the contents of another array

classmethod from_log(log: algopy.Bytes, /) Self
property length: algopy.UInt64

Returns the current length of the array

class algopy.arc4.DynamicBytes

A variable sized array of bytes

__bool__() bool
__iter__() Iterator[algopy.arc4._TArrayItem]
__reversed__() Iterator[algopy.arc4._TArrayItem]
classmethod __subclasshook__(C)
append(item: algopy.arc4._TArrayItem, /) None
copy() Self
extend(other: collections.abc.Iterable[algopy.arc4._TArrayItem], /) None
classmethod from_log(log: algopy.Bytes, /) Self
property length: algopy.UInt64
property native: algopy.Bytes

Return the Bytes representation of the address after ARC4 decoding

class algopy.arc4.StaticArray

A fixed length ARC4 Array of the specified type and length

__iter__() Iterator[algopy.arc4._TArrayItem]

Returns an iterator for the items in the array

__reversed__() Iterator[algopy.arc4._TArrayItem]

Returns an iterator for the items in the array, in reverse order

classmethod __subclasshook__(C)
copy() Self

Create a copy of this array

classmethod from_log(log: algopy.Bytes, /) Self
property length: algopy.UInt64

Returns the current length of the array

class algopy.arc4.String(value: algopy.String | str = '', /)

An ARC4 sequence of bytes containing a UTF8 string

Initialization

__bool__() bool

Returns True if length is not zero

__eq__(other: algopy.arc4.String | str) bool
classmethod from_log(log: algopy.Bytes, /) Self
property native: algopy.String

Return the String representation of the UTF8 string after ARC4 decoding

class algopy.arc4.Struct

Base class for ARC4 Struct types

property bytes: algopy.Bytes

Get the underlying bytes[]

copy() Self

Create a copy of this struct

classmethod from_bytes(value: algopy.Bytes | bytes, /) Self

Construct an instance from the underlying bytes[] (no validation)

classmethod from_log(log: algopy.Bytes, /) Self

Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75

class algopy.arc4.Tuple(items: tuple[Unpack[algopy.arc4._TTuple]], /)

An ARC4 ABI tuple, containing other ARC4 ABI types

Initialization

Construct an ARC4 tuple from a python tuple

__add__()
__contains__()
__delattr__()
__dir__()
__eq__()
__format__()
__ge__()
__getattribute__()
__getitem__()
__getstate__()
__gt__()
__hash__()
__iter__()
__le__()
__len__()
__lt__()
__mul__()
__ne__()
__new__()
__reduce__()
__reduce_ex__()
__repr__()
__rmul__()
__setattr__()
__sizeof__()
__str__()
__subclasshook__()
count()
classmethod from_log(log: algopy.Bytes, /) Self
index()
property native: tuple[Unpack[algopy.arc4._TTuple]]

Return the Bytes representation of the address after ARC4 decoding

class algopy.arc4.UFixedNxM(value: str = '0.0', /)

An ARC4 UFixed representing a decimal with the number of bits and precision specified.

Max size: 64 bits

Initialization

Construct an instance of UFixedNxM where value (v) is determined from the original decimal value (d) by the formula v = round(d * (10^M))

__bool__() bool

Returns True if not equal to zero

classmethod from_log(log: algopy.Bytes, /) Self
algopy.arc4.UInt128: TypeAlias

None

An ARC4 UInt128

algopy.arc4.UInt16: TypeAlias

None

An ARC4 UInt16

algopy.arc4.UInt256: TypeAlias

None

An ARC4 UInt256

algopy.arc4.UInt32: TypeAlias

None

An ARC4 UInt32

algopy.arc4.UInt512: TypeAlias

None

An ARC4 UInt512

algopy.arc4.UInt64: TypeAlias

None

An ARC4 UInt64

algopy.arc4.UInt8: TypeAlias

None

An ARC4 UInt8

class algopy.arc4.UIntN(value: algopy.BigUInt | algopy.UInt64 | int = 0, /)

An ARC4 UInt consisting of the number of bits specified.

Max Size: 64 bits

Initialization

__bool__() bool
__eq__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__ge__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__gt__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__le__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__lt__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
__ne__(
other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
) bool
classmethod from_log(log: algopy.Bytes, /) Self
property native: algopy.UInt64

Return the UInt64 representation of the value after ARC4 decoding

algopy.arc4.abi_call: algopy.arc4._ABICallProtocolType

Ellipsis

Provides a typesafe way of calling ARC4 methods via an inner transaction

Examples:

# can reference another algopy contract method
result, txn = abi_call(HelloWorldContract.hello, arc4.String("World"), app=...)
assert result == "Hello, World"

# can reference a method selector
result, txn = abi_call[arc4.String]("hello(string)string", arc4.String("Algo"), app=...)
assert result == "Hello, Algo"

# can reference a method name, the method selector is inferred from arguments and return type
result, txn = abi_call[arc4.String]("hello", "There", app=...)
assert result == "Hello, There"
algopy.arc4.abimethod(
*,
name: str = ...,
create: Literal[allow, require, disallow] = 'disallow',
allow_actions: collections.abc.Sequence[algopy.OnCompleteAction | Literal[NoOp, OptIn, CloseOut, UpdateApplication, DeleteApplication]] = ('NoOp',),
readonly: bool = False,
default_args: collections.abc.Mapping[str, str | algopy.arc4._TABIDefaultArgSource] = ...,
) collections.abc.Callable[[collections.abc.Callable[algopy.arc4._P, algopy.arc4._R]], collections.abc.Callable[algopy.arc4._P, algopy.arc4._R]]

Decorator that indicates a method is an ARC4 ABI method.

Parameters:
  • name – Name component of the ABI method selector. Defaults to using the function name.

  • create – Controls the validation of the Application ID. “require” means it must be zero, “disallow” requires it must be non-zero, and “allow” disables the validation.

  • allow_actions – A sequence of allowed On-Completion Actions to validate against.

  • readonly – If True, then this method can be used via dry-run / simulate.

  • default_args – Default argument sources for clients to use.

algopy.arc4.arc4_signature(signature: str, /) algopy.Bytes

Returns the ARC4 encoded method selector for the specified signature

algopy.arc4.baremethod(
*,
create: Literal[allow, require, disallow] = 'disallow',
allow_actions: collections.abc.Sequence[algopy.OnCompleteAction | Literal[NoOp, OptIn, CloseOut, UpdateApplication, DeleteApplication]] = ...,
) collections.abc.Callable[[collections.abc.Callable[algopy.arc4._P, algopy.arc4._R]], collections.abc.Callable[algopy.arc4._P, algopy.arc4._R]]

Decorator that indicates a method is an ARC4 bare method.

There can be only one bare method on a contract for each given On-Completion Action.

Parameters:
  • create – Controls the validation of the Application ID. “require” means it must be zero, “disallow” requires it must be non-zero, and “allow” disables the validation.

  • allow_actions – Which On-Completion Action(s) to handle.

algopy.arc4.emit(event: str | algopy.arc4.Struct, /, *args: algopy.arc4._TABIArg) None

Emit an ARC-28 event for the provided event signature or name, and provided args.

Parameters:
  • event

    Either an ARC4 Struct, an event name, or event signature.

    • If event is an ARC4 Struct, the event signature will be determined from the Struct name and fields

    • If event is a signature, then the following args will be typed checked to ensure they match.

    • If event is just a name, the event signature will be inferred from the name and following arguments

  • args – When event is a signature or name, args will be used as the event data. They will all be encoded as single ARC4 Tuple

Example:

from algopy import ARC4Contract, arc4


class Swapped(arc4.Struct):
    a: arc4.UInt64
    b: arc4.UInt64


class EventEmitter(ARC4Contract):
    @arc4.abimethod
    def emit_swapped(self, a: arc4.UInt64, b: arc4.UInt64) -> None:
        arc4.emit(Swapped(b, a))
        arc4.emit("Swapped(uint64,uint64)", b, a)
        arc4.emit("Swapped", b, a)