Skip to content

algopy.arc4

ARC4ClientUsed to provide typed method signatures for ARC4 contracts
ARC4ContractThe base class for a contract that conforms to the ARC4 ABI specification. Most contracts
should inherit from this class or a superclass thereof.
AddressAn alias for an array containing 32 bytes representing an Algorand address
BigUFixedNxMAn ARC4 UFixed representing a decimal with the number of bits and precision specified.
BigUIntNAn ARC4 UInt consisting of the number of bits specified.
BoolAn ARC4 encoded bool. The most significant bit is 1 for True and 0 for False
ByteAn ARC4 alias for a UInt8
DynamicArrayA dynamically sized ARC4 Array of the specified type
DynamicBytesA variable sized array of bytes
StaticArrayA fixed length ARC4 Array of the specified type and length
StringAn ARC4 sequence of bytes containing a UTF8 string.
StructBase class for ARC4 Struct types. ARC4 Structs are named tuples. The class keyword frozen
can be used to indicate if a struct can be mutated.
TupleAn ARC4 ABI tuple, containing other ARC4 ABI types. ARC4 Tuples are immutable statically
sized arrays of mixed item types. Item types can be specified via generic parameters or
inferred from constructor parameters.
UFixedNxMAn ARC4 UFixed representing a decimal with the number of bits and precision specified.
UIntNAn ARC4 UInt consisting of the number of bits specified (big-endian encoded).
abimethodDecorator that indicates a method is an ARC4 ABI method. If the method should not be externally
callable, use algopy.subroutine() instead.
arc4_createProvides a typesafe and convenient way of creating an ARC4Contract via an inner transaction
arc4_signatureReturns the ARC4 encoded method selector for the specified signature
arc4_updateProvides a typesafe and convenient way of updating an ARC4Contract via an inner transaction
baremethodDecorator that indicates a method is an ARC4 bare method.
emitEmit an ARC-28 event for the provided event signature or name, and provided args.
UInt128An ARC4 UInt128
UInt16An ARC4 UInt16
UInt256An ARC4 UInt256
UInt32An ARC4 UInt32
UInt512An ARC4 UInt512
UInt64An ARC4 UInt64
UInt8An ARC4 UInt8
abi_callProvides a typesafe way of calling ARC4 methods via an inner transaction

ARC4Client

Used to provide typed method signatures for ARC4 contracts

ARC4Contract

The base class for a contract that conforms to the ARC4 ABI specification. Most contracts should inherit from this class or a superclass thereof.

class HelloWorldContract(ARC4Contract):
# ...

Functions decorated with algopy.arc4.abimethod() or algopy.arc4.baremethod() will form the public interface of the contract.

The algopy.arc4.ARC4Contract.approval_program() will be implemented by the compiler, and route application args according to the ARC4 ABI specification.

The algopy.arc4.ARC4Contract.clear_state_program() will by default return True, but can be overridden

The Puya compiler will generate ARC32 and ARC56 application specifications for the contract automatically.

init_subclass(*, name: str = …, scratch_slots: algopy.urange | tuple[int | algopy.urange, …] | list[int | algopy.urange] = …, state_totals: algopy.StateTotals = …, avm_version: int = …)

When declaring a Contract subclass, options and configuration are passed in the base class list:

class MyContract(algopy.Contract, name="CustomName"):
...

:param name: Will affect the output TEAL file name if there are multiple non-abstract contracts in the same file.

If the contract is a subclass of algopy.ARC4Contract, name will also be used as the contract name in the ARC-32 application.json, instead of the class name.

:param scratch_slots: Allows you to mark a slot ID or range of slot IDs as “off limits” to Puya. These slot ID(s) will never be written to or otherwise manipulating by the compiler itself. This is particularly useful in combination with algopy.op.gload_bytes / algopy.op.gload_uint64 which lets a contract in a group transaction read from the scratch slots of another contract that occurs earlier in the transaction group.

In the case of inheritance, scratch slots reserved become cumulative. It is not an error to have overlapping ranges or values either, so if a base class contract reserves slots 0-5 inclusive and the derived contract reserves 5-10 inclusive, then within the derived contract all slots 0-10 will be marked as reserved.

:param state_totals: Allows defining what values should be used for global and local uint and bytes storage values when creating a contract. Used when outputting ARC-32 application.json schemas.

If let unspecified, the totals will be determined by the compiler based on state variables assigned to self.

This setting is not inherited, and only applies to the exact Contract it is specified on. If a base class does specify this setting, and a derived class does not, a warning will be emitted for the derived class. To resolve this warning, state_totals must be specified. Note that it is valid to not provide any arguments to the StateTotals constructor, like so state_totals=StateTotals(), in which case all values will be automatically calculated. :param avm_version: Determines which AVM version to use, this affects what operations are supported. Defaults to value provided supplied on command line (which defaults to current mainnet version)

approval_program() → bool

The approval program for the ARC4Contract is implemented by the compile in accordance with ARC4

clear_state_program() → algopy.UInt64 | bool

The clear_state_program contains the logic when the OnCompletion is ClearState.

The default implementation simply returns True, but this can be overridden.

ClearState transactions always clear local state of the sender. Documentation on ClearState behavior should be read before implementing this method: https://developer.algorand.org/docs/get-details/dapps/smart-contracts/frontend/apps/#clear-state

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

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

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

getitem(index: algopy.UInt64 | int) → algopy.arc4._TArrayItem

Gets the item of the array at provided index

iter() → Iterator[algopy.arc4._TArrayItem]

Returns an iterator for the items in the array

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]

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

setitem(index: algopy.UInt64 | int, value: algopy.arc4._TArrayItem) → algopy.arc4._TArrayItem

Sets the item of the array at specified index to provided value

bytes : algopy.Bytes

Get the underlying Bytes

copy() → Self

Create a copy of this array

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

Construct an instance from the underlying bytes (no validation)

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

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

length : algopy.UInt64

Returns the current length of the array

native : algopy.Account

Return the Account representation of the address after ARC4 decoding

BigUFixedNxM(value: str = ‘0.0’, /)

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

Max size: 512 bits

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

eq(other: Self) → bool

Compare for equality, note both operands must be the exact same type

bytes : algopy.Bytes

Get the underlying Bytes

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

Construct an instance from the underlying bytes (no validation)

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

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

BigUIntN(value: algopy.BigUInt | algopy.UInt64 | int = 0, /)

An ARC4 UInt consisting of the number of bits specified.

Max size: 512 bits

bool() → bool

Returns True if not equal to zero

eq(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self==value.

ge(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self>=value.

gt(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self>value.

le(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self<=value.

lt(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self<value.

ne(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self!=value.

bytes : algopy.Bytes

Get the underlying Bytes

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

Construct an instance from the underlying bytes (no validation)

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

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

native : algopy.BigUInt

Return the BigUInt representation of the value after ARC4 decoding

Bool(value: bool = False, /)

An ARC4 encoded bool. The most significant bit is 1 for True and 0 for False

eq(other: algopy.arc4.Bool | bool) → bool

Return self==value.

ne(other: algopy.arc4.Bool | bool) → bool

Return self!=value.

bytes : algopy.Bytes

Get the underlying Bytes

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

Construct an instance from the underlying bytes (no validation)

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

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

native : bool

Return the bool representation of the value after ARC4 decoding

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

An ARC4 alias for a UInt8

bool() → bool

Returns True if not equal to zero

eq(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self==value.

ge(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self>=value.

gt(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self>value.

le(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self<=value.

lt(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self<value.

ne(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self!=value.

bytes : algopy.Bytes

Get the underlying Bytes

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

Construct an instance from the underlying bytes (no validation)

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

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

native : algopy.UInt64

Return the UInt64 representation of the value after ARC4 decoding

DynamicArray(*items: algopy.arc4._TArrayItem)

A dynamically sized ARC4 Array of the specified type

import typing as t
from algopy import arc4
UInt64Array: t.TypeAlias = arc4.DynamicArray[arc4.UInt64]

Initializes a new array with items provided

add(other: algopy.arc4.DynamicArray[algopy.arc4._TArrayItem] | algopy.arc4.StaticArray[algopy.arc4._TArrayItem, algopy.arc4._TArrayLength] | tuple[algopy.arc4._TArrayItem, …]) → algopy.arc4.DynamicArray[algopy.arc4._TArrayItem]

Concat two arrays together, returning a new array

bool() → bool

Returns True if not an empty array

getitem(index: algopy.UInt64 | int) → algopy.arc4._TArrayItem

Gets the item of the array at provided index

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

setitem(index: algopy.UInt64 | int, value: algopy.arc4._TArrayItem) → algopy.arc4._TArrayItem

Sets the item of the array at specified index to provided value

append(item: algopy.arc4._TArrayItem, /) → None

Append an item to this array

bytes : algopy.Bytes

Get the underlying Bytes

copy() → Self

Create a copy of this array

extend(other: algopy.arc4.DynamicArray[algopy.arc4._TArrayItem] | algopy.arc4.StaticArray[algopy.arc4._TArrayItem, algopy.arc4._TArrayLength] | tuple[algopy.arc4._TArrayItem, …], /) → None

Extend this array with the contents of another array

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

Construct an instance from the underlying bytes (no validation)

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

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

length : algopy.UInt64

Returns the current length of the array

pop() → algopy.arc4._TArrayItem

Remove and return the last item of this array

DynamicBytes

A variable sized array of bytes

add(other: algopy.arc4.DynamicArray[algopy.arc4._TArrayItem] | algopy.arc4.StaticArray[algopy.arc4._TArrayItem, algopy.arc4._TArrayLength] | tuple[algopy.arc4._TArrayItem, …]) → algopy.arc4.DynamicArray[algopy.arc4._TArrayItem]

Concat two arrays together, returning a new array

bool() → bool

Returns True if not an empty array

getitem(index: algopy.UInt64 | int) → algopy.arc4._TArrayItem

Gets the item of the array at provided index

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

setitem(index: algopy.UInt64 | int, value: algopy.arc4._TArrayItem) → algopy.arc4._TArrayItem

Sets the item of the array at specified index to provided value

append(item: algopy.arc4._TArrayItem, /) → None

Append an item to this array

bytes : algopy.Bytes

Get the underlying Bytes

copy() → Self

Create a copy of this array

extend(other: algopy.arc4.DynamicArray[algopy.arc4._TArrayItem] | algopy.arc4.StaticArray[algopy.arc4._TArrayItem, algopy.arc4._TArrayLength] | tuple[algopy.arc4._TArrayItem, …], /) → None

Extend this array with the contents of another array

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

Construct an instance from the underlying bytes (no validation)

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

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

length : algopy.UInt64

Returns the current length of the array

native : algopy.Bytes

Return the Bytes representation of the address after ARC4 decoding

pop() → algopy.arc4._TArrayItem

Remove and return the last item of this array

StaticArray

A fixed length ARC4 Array of the specified type and length

import typing as t
from algopy import arc4
FourBytes: t.TypeAlias = arc4.StaticArray[arc4.Byte, t.Literal[4]]

getitem(index: algopy.UInt64 | int) → algopy.arc4._TArrayItem

Gets the item of the array at provided index

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

setitem(index: algopy.UInt64 | int, value: algopy.arc4._TArrayItem) → algopy.arc4._TArrayItem

Sets the item of the array at specified index to provided value

bytes : algopy.Bytes

Get the underlying Bytes

copy() → Self

Create a copy of this array

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

Construct an instance from the underlying bytes (no validation)

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

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

length : algopy.UInt64

Returns the current length of the array

String(value: algopy.String | str = ”, /)

An ARC4 sequence of bytes containing a UTF8 string.

The length is the number of bytes, NOT the number of characters

bool() → bool

Returns True if length is not zero

eq(other: algopy.arc4.String | algopy.String | str) → bool

Return self==value.

bytes : algopy.Bytes

Get the underlying Bytes

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

Construct an instance from the underlying bytes (no validation)

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

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

native : algopy.String

Return the String representation of the UTF8 string after ARC4 decoding

Struct

Base class for ARC4 Struct types. ARC4 Structs are named tuples. The class keyword frozen can be used to indicate if a struct can be mutated.

Items can be accessed and mutated via names instead of indexes. Structs do not have a .native property, but a NamedTuple can be used in ABI methods are will be encoded/decode to an ARC4 struct automatically.

import typing
from algopy import arc4
Decimal: typing.TypeAlias = arc4.UFixedNxM[typing.Literal[64], typing.Literal[9]]
class Vector(arc4.Struct, kw_only=True, frozen=True):
x: Decimal
y: Decimal

bytes : algopy.Bytes

Get the underlying bytes[]

copy() → Self

Create a copy of this struct

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

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

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

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

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

An ARC4 ABI tuple, containing other ARC4 ABI types. ARC4 Tuples are immutable statically sized arrays of mixed item types. Item types can be specified via generic parameters or inferred from constructor parameters.

Construct an ARC4 tuple from a native Python tuple

add()

Return self+value.

contains()

Return bool(key in self).

delattr()

Implement delattr(self, name).

dir()

Default dir() implementation.

eq()

Return self==value.

format()

Default object formatter.

Return str(self) if format_spec is empty. Raise TypeError otherwise.

ge()

Return self>=value.

getattribute()

Return getattr(self, name).

getitem()

Return self[key].

getstate()

Helper for pickle.

gt()

Return self>value.

hash()

Return hash(self).

iter()

Implement iter(self).

le()

Return self<=value.

len()

Return len(self).

lt()

Return self<value.

mul()

Return self*value.

ne()

Return self!=value.

new()

Create and return a new object. See help(type) for accurate signature.

reduce()

Helper for pickle.

reduce_ex()

Helper for pickle.

repr()

Return repr(self).

rmul()

Return value*self.

setattr()

Implement setattr(self, name, value).

sizeof()

Size of object in memory, in bytes.

str()

Return str(self).

bytes : algopy.Bytes

Get the underlying Bytes

copy() → Self

Create a copy of this tuple

count()

Return number of occurrences of value.

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

Construct an instance from the underlying bytes (no validation)

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

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

index()

Return first index of value.

Raises ValueError if the value is not present.

native : tuple[Unpack[algopy.arc4._TTuple]]

Convert to a native Python tuple - note that the elements of the tuple should be considered to be copies of the original elements

UFixedNxM(value: str = ‘0.0’, /)

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

Max size: 64 bits

import typing as t
from algopy import arc4
Decimal: t.TypeAlias = arc4.UFixedNxM[t.Literal[64], t.Literal[10]]

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

eq(other: Self) → bool

Compare for equality, note both operands must be the exact same type

bytes : algopy.Bytes

Get the underlying Bytes

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

Construct an instance from the underlying bytes (no validation)

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

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

UInt128 : TypeAlias

None

An ARC4 UInt128

UInt16 : TypeAlias

None

An ARC4 UInt16

UInt256 : TypeAlias

None

An ARC4 UInt256

UInt32 : TypeAlias

None

An ARC4 UInt32

UInt512 : TypeAlias

None

An ARC4 UInt512

UInt64 : TypeAlias

None

An ARC4 UInt64

UInt8 : TypeAlias

None

An ARC4 UInt8

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

An ARC4 UInt consisting of the number of bits specified (big-endian encoded).

Common bit sizes have also been aliased under algopy.arc4.UInt8, algopy.arc4.UInt16 etc.

A uint of any size between 8 and 512 bits (in intervals of 8bits) can be created using a generic parameter. It can be helpful to define your own alias for this type.

import typing as t
from algopy import arc4
UInt40: t.TypeAlias = arc4.UIntN[t.Literal[40]]

Max Size: 64 bits

bool() → bool

Returns True if not equal to zero

eq(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self==value.

ge(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self>=value.

gt(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self>value.

le(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self<=value.

lt(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self<value.

ne(other: algopy.arc4.UIntN[algopy.arc4._TBitSize] | algopy.arc4.BigUIntN[algopy.arc4._TBitSize] | algopy.UInt64 | algopy.BigUInt | int) → bool

Return self!=value.

bytes : algopy.Bytes

Get the underlying Bytes

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

Construct an instance from the underlying bytes (no validation)

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

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

native : algopy.UInt64

Return the UInt64 representation of the value after ARC4 decoding

abi_call : algopy.arc4._ABICallProtocolType

Ellipsis

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

def abi_call(
self,
method: Callable[..., _TABIResult_co] | str,
/,
*args: _TABIArg,
app_id: algopy.Application | algopy.UInt64 | int = ...,
on_completion: algopy.OnCompleteAction = ...,
approval_program: algopy.Bytes | bytes | tuple[algopy.Bytes, ...] = ...,
clear_state_program: algopy.Bytes | bytes | tuple[algopy.Bytes, ...] = ...,
global_num_uint: UInt64 | int = ...,
global_num_bytes: UInt64 | int = ...,
local_num_uint: UInt64 | int = ...,
local_num_bytes: UInt64 | int = ...,
extra_program_pages: UInt64 | int = ...,
fee: algopy.UInt64 | int = 0,
sender: algopy.Account | str = ...,
note: algopy.Bytes | algopy.String | bytes | str = ...,
rekey_to: algopy.Account | str = ...,
) -> tuple[_TABIResult_co, algopy.itxn.ApplicationCallInnerTransaction]: ...

PARAMETERS:

method: The name, method selector or Algorand Python method to call<br /> \\ app_id: Application to call, if 0 or not specified will create a new application<br /> \\ on_completion: OnCompleteAction value for the transaction. If not specified will be inferred from Algorand Python method where possible<br /> \\ approval_program: When creating or updating an application, the approval program<br /> \\ clear_state_program: When creating or updating an application, the clear state program<br /> \\ global_num_uint: When creating an application the number of global uints<br /> \\ global_num_bytes: When creating an application the number of global bytes<br /> \\ local_num_uint: When creating an application the number of local uints<br /> \\ local_num_bytes: When creating an application the number of local bytes<br /> \\ extra_program_pages: When creating an application the The number of extra program pages<br /> \\ fee: The fee to pay for the transaction, defaults to 0<br /> \\ sender: The sender address for the transaction<br /> \\ note: Note to include with the transaction<br /> \\ rekey_to: Account to rekey to

RETURNS:<br /> \\ If method references an Algorand Contract / Client or the function is indexed with a return type, then the result is a tuple containing the ABI result and the inner transaction of the call.

If no return type is specified, or the method does not have a return value then the result is the inner transaction of the call.

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"
# calling a method without a return value
txn = abi_call(HelloWorldContract.no_return, arc4.String("World"), app=...)

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._ReadOnlyNoArgsMethod] = …) → 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. If the method should not be externally callable, use algopy.subroutine() instead.

Method docstrings will be used when outputting ARC-32 or ARC-56 application specifications, the following docstrings styles are supported ReST, Google, Numpydoc-style and Epydoc.

from algopy import ARC4Contract, subroutine, arc4
class HelloWorldContract(ARC4Contract):
@arc4.abimethod(create=False, allow_actions=["NoOp", "OptIn"], name="external_name")
def hello(self, name: arc4.String) -> arc4.String:
return self.internal_method() + name
@subroutine
def internal_method(self) -> arc4.String:
return arc4.String("Hello, ")

:arg name: Name component of the ABI method selector. Defaults to using the function name. :arg 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. :arg allow_actions: A sequence of allowed On-Completion Actions to validate against. :arg readonly: If True, then this method can be used via dry-run / simulate. :arg default_args: Default argument sources for clients to use.

arc4_create(method: collections.abc.Callable[algopy.arc4._P, algopy.arc4._TABIResult_co], /, *args: object, compiled: algopy.CompiledContract = …, on_completion: algopy.OnCompleteAction = …, fee: algopy.UInt64 | int = 0, sender: algopy.Account | str = …, note: algopy.Bytes | bytes | str = …, rekey_to: algopy.Account | str = …) → tuple[algopy.arc4._TABIResult_co, algopy.itxn.ApplicationCallInnerTransaction]

Provides a typesafe and convenient way of creating an ARC4Contract via an inner transaction

:param method: An ARC4 create method (ABI or bare), or an ARC4Contract with a single create method :param args: ABI args for chosen method :param compiled: If supplied will be used to specify transaction parameters required for creation, can be omitted if template variables are not used :param on_completion: OnCompleteAction value for the transaction If not specified will be inferred from Algorand Python method where possible :param fee: The fee to pay for the transaction, defaults to 0 :param sender: The sender address for the transaction :param note: Note to include with the transaction :param rekey_to: Account to rekey to

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

Returns the ARC4 encoded method selector for the specified signature

arc4_update(method: collections.abc.Callable[algopy.arc4._P, algopy.arc4._TABIResult_co], /, *args: object, app_id: algopy.Application | algopy.UInt64 | int, compiled: algopy.CompiledContract = …, fee: algopy.UInt64 | int = 0, sender: algopy.Account | str = …, note: algopy.Bytes | bytes | str = …, rekey_to: algopy.Account | str = …) → tuple[algopy.arc4._TABIResult_co, algopy.itxn.ApplicationCallInnerTransaction]

Provides a typesafe and convenient way of updating an ARC4Contract via an inner transaction

:param method: An ARC4 update method (ABI or bare), or an ARC4Contract with a single update method :param args: ABI args for chosen method :param app_id: Application to update :param compiled: If supplied will be used to specify transaction parameters required for updating, can be omitted if template variables are not used :param fee: The fee to pay for the transaction, defaults to 0 :param sender: The sender address for the transaction :param note: Note to include with the transaction :param rekey_to: Account to rekey to

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._TARC4Contract], None]], collections.abc.Callable[[algopy.arc4._TARC4Contract], None]]

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.

:arg 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. :arg allow_actions: Which On-Completion Action(s) to handle.

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

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

:param 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

:param 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)