algopy.arc4
¶
Module Contents¶
Classes¶
A contract that conforms to the ARC4 ABI specification, functions decorated with
|
|
An alias for an array containing 32 bytes representing an Algorand address |
|
An ARC4 UFixed representing a decimal with the number of bits and precision specified. |
|
An ARC4 UInt consisting of the number of bits specified. |
|
An ARC4 encoded bool |
|
An ARC4 alias for a UInt8 |
|
A dynamically sized ARC4 Array of the specified type |
|
A variable sized array of bytes |
|
A fixed length ARC4 Array of the specified type and length |
|
An ARC4 sequence of bytes containing a UTF8 string |
|
Base class for ARC4 Struct types |
|
An ARC4 ABI tuple, containing other ARC4 ABI types |
|
An ARC4 UFixed representing a decimal with the number of bits and precision specified. |
|
An ARC4 UInt consisting of the number of bits specified. |
Functions¶
Decorator that indicates a method is an ARC4 ABI method. |
|
Returns the ARC4 encoded method selector for the specified signature |
|
Decorator that indicates a method is an ARC4 bare method. |
|
Emit an ARC-28 event for the provided event signature or name, and provided args. |
Data¶
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 contractThe 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. Ifvalue
is a Bytes, it’s length checked to be 32 bytes - to avoid this check, useAddress.from_bytes(...)
instead. Defaults 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
orstr
- __ne__(other: algopy.arc4.Address | algopy.Account | str) bool ¶
Address equality is determined by the address of another
arc4.Address
,Account
orstr
- classmethod __subclasshook__(C)¶
- 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))
- 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
- __eq__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __ge__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __gt__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __le__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __lt__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __ne__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- 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 ¶
- class algopy.arc4.Byte(value: algopy.BigUInt | algopy.UInt64 | int = 0, /)¶
An ARC4 alias for a UInt8
Initialization
- __eq__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __ge__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __gt__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __le__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __lt__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __ne__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- 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
- __reversed__() Iterator[algopy.arc4._TArrayItem] ¶
Returns an iterator for the items in the array, in reverse order
- classmethod __subclasshook__(C)¶
- 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
- classmethod __subclasshook__(C)¶
- 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
- __reversed__() Iterator[algopy.arc4._TArrayItem] ¶
Returns an iterator for the items in the array, in reverse order
- classmethod __subclasshook__(C)¶
- 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
- __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[]
- 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()¶
- 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))
- classmethod from_log(log: algopy.Bytes, /) Self ¶
- 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
- __eq__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __ge__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __gt__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __le__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __lt__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- __ne__(
- other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int,
- 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] = ...,
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]] = ...,
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)