algopy.arc4
Module Contents
Section titled “Module Contents”Classes
Section titled “Classes”| Name | Description |
|---|---|
ARC4Contract | A contract that conforms to the ARC-4 ABI specification, functions decorated with@abimethod or @baremethod will form the public interface of the contract |
String | An ARC-4 sequence of bytes containing a UTF8 string |
UIntN | An ARC-4 UInt consisting of the number of bits specified. |
BigUIntN | An ARC-4 UInt consisting of the number of bits specified. |
UFixedNxM | An ARC-4 UFixed representing a decimal with the number of bits and precision specified. |
BigUFixedNxM | An ARC-4 UFixed representing a decimal with the number of bits and precision specified. |
Byte | An ARC-4 alias for a UInt8 |
Bool | An ARC-4 encoded bool |
StaticArray | A fixed length ARC-4 Array of the specified type and length |
DynamicArray | A dynamically sized ARC-4 Array of the specified type |
Address | An alias for an array containing 32 bytes representing an Algorand address |
DynamicBytes | A variable sized array of bytes |
Tuple | An ARC-4 ABI tuple, containing other ARC-4 ABI types |
Struct | Base class for ARC-4 Struct types |
ARC4Client | Used to provide typed method signatures for ARC-4 contracts |
Functions
Section titled “Functions”| Name | Description |
|---|---|
abimethod | Decorator that indicates a method is an ARC-4 ABI method. |
baremethod | Decorator that indicates a method is an ARC-4 bare method. |
arc4_signature | Returns the ARC-4 encoded method selector for the specified signature or abi method |
arc4_create | Provides a typesafe and convenient way of creating an ARC4Contract via an inner transaction |
arc4_update | Provides a typesafe and convenient way of updating an ARC4Contract via an inner transaction |
emit | Emit an ARC-28 event for the provided event signature or name, and provided args. |
encode | Encode a value to ARC-4 bytes. |
decode | Decode ARC-4 encoded bytes to a value of the specified type. |
| Name | Description |
|---|---|
UInt8 | An ARC-4 UInt8 |
UInt16 | An ARC-4 UInt16 |
UInt32 | An ARC-4 UInt32 |
UInt64 | An ARC-4 UInt64 |
UInt128 | An ARC-4 UInt128 |
UInt256 | An ARC-4 UInt256 |
UInt512 | An ARC-4 UInt512 |
abi_call | Provides a typesafe way of calling ARC-4 methods via an inner transaction |
class ARC4Contract
Section titled “class ARC4Contract”Bases: algopy.Contract
A contract that conforms to the ARC-4 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 ARC-4 ABI specification
The clear_state_program will by default return True, but can be overridden
ARC4Contract.approval_program
Section titled “ARC4Contract.approval_program”ARC4Contract.approval_program() → bool
ARC4Contract.clear_state_program
Section titled “ARC4Contract.clear_state_program”ARC4Contract.clear_state_program() → UInt64 | bool
abimethod
Section titled “abimethod”abimethod(*, name: str = …, create: Literal[allow, require, disallow] = ‘disallow’, allow_actions: Sequence[OnCompleteAction | Literal[NoOp, OptIn, CloseOut, UpdateApplication, DeleteApplication]] = (‘NoOp’,), resource_encoding: Literal[index, value] = …, readonly: bool = False, default_args: Mapping[str, str | _ReadOnlyNoArgsMethod | object] = …, validate_encoding: Literal[unsafe_disabled, args] = …) → Callable[[collections.abc.Callable[algopy.arc4._P, _R]], Callable[algopy.arc4._P, _R]]
Decorator that indicates a method is an ARC-4 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.
- resource_encoding – If “index”, then resource types (Application, Asset, Account) should be passed as an index into their appropriate foreign array. The default option “value”, as of PuyaPy 5.0, is for these values to be passed directly. This can be overridden at the compiler level with the “resource_encoding” CLI flag. This option will be reflected in the method signature.
- readonly – If True, then this method can be used via dry-run / simulate.
- default_args – Default argument sources for clients to use. For dynamic defaults, this can be the name of, or reference to a method member, or the name of a storage member. For static defaults, this can be any expression which evaluates to a compile time constant of the exact same type as the parameter.
- validate_encoding – Controls validation behaviour for this method. If “args”, then ABI arguments are validated automatically to ensure they are encoded correctly. If “unsafe_disabled”, then no automatic validation occurs. Arguments can instead be validated using the .validate() method. The default behaviour of this option can be controlled with the –validate-abi-args CLI flag.
baremethod
Section titled “baremethod”baremethod(*, create: Literal[allow, require, disallow] = ‘disallow’, allow_actions: Sequence[OnCompleteAction | Literal[NoOp, OptIn, CloseOut, UpdateApplication, DeleteApplication]] = …) → Callable[[collections.abc.Callable[[_TARC4Contract], None]], Callable[[_TARC4Contract], None]]
Decorator that indicates a method is an ARC-4 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.
arc4_signature
Section titled “arc4_signature”arc4_signature(signature: str | Callable[algopy.arc4._P, _R], /) → Bytes
Returns the ARC-4 encoded method selector for the specified signature or abi method
class String
Section titled “class String”String(value: String | str = ”, /)
Bases: algopy.arc4._ABIEncoded
An ARC-4 sequence of bytes containing a UTF8 string
Initialization
Section titled “Initialization”A String can be initialized with a Python str literal, or a str variable
declared at the module level
property String.native : String
Section titled “property String.native : String”Return the String representation of the UTF8 string after ARC-4 decoding
String.__add__
Section titled “String.__add__”String.__iadd__
Section titled “String.__iadd__”String.__radd__
Section titled “String.__radd__”String.__eq__
Section titled “String.__eq__”Return self==value.
String.__bool__
Section titled “String.__bool__”String.__bool__() → bool
Returns True if length is not zero
classmethod String.from_log
Section titled “classmethod String.from_log”String.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
String.validate
Section titled “String.validate”String.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
class UIntN
Section titled “class UIntN”Bases: algopy.arc4._UIntN, typing.Generic[algopy.arc4._TBitSize]
An ARC-4 UInt consisting of the number of bits specified.
Max Size: 64 bits
property UIntN.native : UInt64
Section titled “property UIntN.native : UInt64”Return the UInt64 representation of the value after ARC-4 decoding
UIntN.as_uint64
Section titled “UIntN.as_uint64”UIntN.as_uint64() → UInt64
Return the UInt64 representation of the value after ARC-4 decoding
UIntN.as_biguint
Section titled “UIntN.as_biguint”UIntN.as_biguint() → BigUInt
Return the BigUInt representation of the value after ARC-4 decoding
classmethod UIntN.from_log
Section titled “classmethod UIntN.from_log”UIntN.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
UIntN.validate
Section titled “UIntN.validate”UIntN.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
class BigUIntN
Section titled “class BigUIntN”Bases: algopy.arc4._UIntN, typing.Generic[algopy.arc4._TBitSize]
An ARC-4 UInt consisting of the number of bits specified.
Max size: 512 bits
property BigUIntN.native : BigUInt
Section titled “property BigUIntN.native : BigUInt”Return the BigUInt representation of the value after ARC-4 decoding
BigUIntN.as_uint64
Section titled “BigUIntN.as_uint64”BigUIntN.as_uint64() → UInt64
Return the UInt64 representation of the value after ARC-4 decoding
BigUIntN.as_biguint
Section titled “BigUIntN.as_biguint”BigUIntN.as_biguint() → BigUInt
Return the BigUInt representation of the value after ARC-4 decoding
classmethod BigUIntN.from_log
Section titled “classmethod BigUIntN.from_log”BigUIntN.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
BigUIntN.validate
Section titled “BigUIntN.validate”BigUIntN.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
class UFixedNxM
Section titled “class UFixedNxM”UFixedNxM(value: str = ‘0.0’, /)
Bases: algopy.arc4._ABIEncoded, typing.Generic[algopy.arc4._TBitSize, algopy.arc4._TDecimalPlaces]
An ARC-4 UFixed representing a decimal with the number of bits and precision specified.
Max size: 64 bits
Initialization
Section titled “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))
UFixedNxM.__bool__
Section titled “UFixedNxM.__bool__”UFixedNxM.__bool__() → bool
Returns True if not equal to zero
UFixedNxM.__eq__
Section titled “UFixedNxM.__eq__”UFixedNxM.__eq__(other: Self) → bool
Compare for equality, note both operands must be the exact same type
classmethod UFixedNxM.from_log
Section titled “classmethod UFixedNxM.from_log”UFixedNxM.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
UFixedNxM.validate
Section titled “UFixedNxM.validate”UFixedNxM.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
class BigUFixedNxM
Section titled “class BigUFixedNxM”BigUFixedNxM(value: str = ‘0.0’, /)
Bases: algopy.arc4._ABIEncoded, typing.Generic[algopy.arc4._TBitSize, algopy.arc4._TDecimalPlaces]
An ARC-4 UFixed representing a decimal with the number of bits and precision specified.
Max size: 512 bits
Initialization
Section titled “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))
BigUFixedNxM.__bool__
Section titled “BigUFixedNxM.__bool__”BigUFixedNxM.__bool__() → bool
Returns True if not equal to zero
BigUFixedNxM.__eq__
Section titled “BigUFixedNxM.__eq__”BigUFixedNxM.__eq__(other: Self) → bool
Compare for equality, note both operands must be the exact same type
classmethod BigUFixedNxM.from_log
Section titled “classmethod BigUFixedNxM.from_log”BigUFixedNxM.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
BigUFixedNxM.validate
Section titled “BigUFixedNxM.validate”BigUFixedNxM.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
class Byte
Section titled “class Byte”Bases: algopy.arc4.UIntN[typing.Literal[8]]
An ARC-4 alias for a UInt8
property Byte.native : UInt64
Section titled “property Byte.native : UInt64”Return the UInt64 representation of the value after ARC-4 decoding
Byte.as_uint64
Section titled “Byte.as_uint64”Byte.as_uint64() → UInt64
Return the UInt64 representation of the value after ARC-4 decoding
Byte.as_biguint
Section titled “Byte.as_biguint”Byte.as_biguint() → BigUInt
Return the BigUInt representation of the value after ARC-4 decoding
classmethod Byte.from_log
Section titled “classmethod Byte.from_log”Byte.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
Byte.validate
Section titled “Byte.validate”Byte.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
UInt8 : TypeAlias
Section titled “UInt8 : TypeAlias”An ARC-4 UInt8
UInt16 : TypeAlias
Section titled “UInt16 : TypeAlias”An ARC-4 UInt16
UInt32 : TypeAlias
Section titled “UInt32 : TypeAlias”An ARC-4 UInt32
UInt64 : TypeAlias
Section titled “UInt64 : TypeAlias”An ARC-4 UInt64
UInt128 : TypeAlias
Section titled “UInt128 : TypeAlias”An ARC-4 UInt128
UInt256 : TypeAlias
Section titled “UInt256 : TypeAlias”An ARC-4 UInt256
UInt512 : TypeAlias
Section titled “UInt512 : TypeAlias”An ARC-4 UInt512
class Bool
Section titled “class Bool”Bool(value: bool = False, /)
Bases: algopy.arc4._ABIEncoded
An ARC-4 encoded bool
Bool.__eq__
Section titled “Bool.__eq__”Bool.__eq__(other: Bool | bool) → bool
Return self==value.
Bool.__ne__
Section titled “Bool.__ne__”Bool.__ne__(other: Bool | bool) → bool
Return self!=value.
property Bool.native : bool
Section titled “property Bool.native : bool”Return the bool representation of the value after ARC-4 decoding
classmethod Bool.from_log
Section titled “classmethod Bool.from_log”Bool.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
Bool.validate
Section titled “Bool.validate”Bool.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
class StaticArray
Section titled “class StaticArray”Bases: algopy.arc4._ABIEncoded, typing.Generic[algopy.arc4._TArrayItem, algopy.arc4._TArrayLength], collections.abc.Reversible[algopy.arc4._TArrayItem]
A fixed length ARC-4 Array of the specified type and length
StaticArray.__iter__
Section titled “StaticArray.__iter__”StaticArray.__iter__() → Iterator[_TArrayItem]
Returns an iterator for the items in the array
StaticArray.__reversed__
Section titled “StaticArray.__reversed__”StaticArray.__reversed__() → Iterator[_TArrayItem]
Returns an iterator for the items in the array, in reverse order
property StaticArray.length : UInt64
Section titled “property StaticArray.length : UInt64”Returns the (compile-time) length of the array
StaticArray.__getitem__
Section titled “StaticArray.__getitem__”StaticArray.__getitem__(index: UInt64 | int) → _TArrayItem
Gets the item of the array at provided index
StaticArray.__setitem__
Section titled “StaticArray.__setitem__”StaticArray.__setitem__(index: UInt64 | int, value: _TArrayItem) → _TArrayItem
Sets the item of the array at specified index to provided value
StaticArray.copy
Section titled “StaticArray.copy”StaticArray.copy() → Self
Create a copy of this array
StaticArray.to_native
Section titled “StaticArray.to_native”StaticArray.to_native(element_type: type[_TNativeArrayItem], /) → FixedArray[algopy.arc4._TNativeArrayItem, _TArrayLength]
Convert to an algopy.FixedArray with the specified element type.
Only allowed if the element type is compatible with this arrays element type e.g. arc4.UInt64 -> UInt64
classmethod StaticArray.from_log
Section titled “classmethod StaticArray.from_log”StaticArray.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
StaticArray.validate
Section titled “StaticArray.validate”StaticArray.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
class DynamicArray
Section titled “class DynamicArray”DynamicArray(*items: _TArrayItem)
Bases: algopy.arc4._ABIEncoded, typing.Generic[algopy.arc4._TArrayItem], collections.abc.Reversible[algopy.arc4._TArrayItem]
A dynamically sized ARC-4 Array of the specified type
Initialization
Section titled “Initialization”Initializes a new array with items provided
DynamicArray.__iter__
Section titled “DynamicArray.__iter__”DynamicArray.__iter__() → Iterator[_TArrayItem]
Returns an iterator for the items in the array
DynamicArray.__reversed__
Section titled “DynamicArray.__reversed__”DynamicArray.__reversed__() → Iterator[_TArrayItem]
Returns an iterator for the items in the array, in reverse order
property DynamicArray.length : UInt64
Section titled “property DynamicArray.length : UInt64”Returns the current length of the array
DynamicArray.__getitem__
Section titled “DynamicArray.__getitem__”DynamicArray.__getitem__(index: UInt64 | int) → _TArrayItem
Gets the item of the array at provided index
DynamicArray.append
Section titled “DynamicArray.append”DynamicArray.append(item: _TArrayItem, /) → None
Append an item to this array
DynamicArray.extend
Section titled “DynamicArray.extend”DynamicArray.extend(other: Iterable[_TArrayItem], /) → None
Extend this array with the contents of another array
DynamicArray.__setitem__
Section titled “DynamicArray.__setitem__”DynamicArray.__setitem__(index: UInt64 | int, value: _TArrayItem) → _TArrayItem
Sets the item of the array at specified index to provided value
DynamicArray.__add__
Section titled “DynamicArray.__add__”DynamicArray.__add__(other: Iterable[_TArrayItem]) → DynamicArray[_TArrayItem]
Concat two arrays together, returning a new array
DynamicArray.pop
Section titled “DynamicArray.pop”DynamicArray.pop() → _TArrayItem
Remove and return the last item of this array
DynamicArray.copy
Section titled “DynamicArray.copy”DynamicArray.copy() → Self
Create a copy of this array
DynamicArray.__bool__
Section titled “DynamicArray.__bool__”DynamicArray.__bool__() → bool
Returns True if not an empty array
DynamicArray.to_native
Section titled “DynamicArray.to_native”DynamicArray.to_native(element_type: type[_TNativeArrayItem], /) → Array[_TNativeArrayItem]
Convert to an algopy.Array with the specified element type.
Only allowed if the element type is compatible with this arrays element type e.g. arc4.UInt64 -> UInt64
classmethod DynamicArray.from_log
Section titled “classmethod DynamicArray.from_log”DynamicArray.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
DynamicArray.validate
Section titled “DynamicArray.validate”DynamicArray.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
class Address
Section titled “class Address”Bases: algopy.arc4.StaticArray[algopy.arc4.Byte, typing.Literal[32]]
An alias for an array containing 32 bytes representing an Algorand address
Initialization
Section titled “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.
property Address.native : Account
Section titled “property Address.native : Account”Return the Account representation of the address after ARC-4 decoding
Address.__bool__
Section titled “Address.__bool__”Address.__bool__() → bool
Returns True if not equal to the zero address
Address.__eq__
Section titled “Address.__eq__”Address equality is determined by the address of another
arc4.Address, Account or str
Address.__ne__
Section titled “Address.__ne__”Address equality is determined by the address of another
arc4.Address, Account or str
property Address.length : UInt64
Section titled “property Address.length : UInt64”Returns the (compile-time) length of the array
Address.copy
Section titled “Address.copy”Address.copy() → Self
Create a copy of this array
Address.to_native
Section titled “Address.to_native”Address.to_native(element_type: type[_TNativeArrayItem], /) → FixedArray[algopy.arc4._TNativeArrayItem, _TArrayLength]
Convert to an algopy.FixedArray with the specified element type.
Only allowed if the element type is compatible with this arrays element type e.g. arc4.UInt64 -> UInt64
classmethod Address.from_log
Section titled “classmethod Address.from_log”Address.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
Address.validate
Section titled “Address.validate”Address.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
class DynamicBytes
Section titled “class DynamicBytes”Bases: algopy.arc4.DynamicArray[algopy.arc4.Byte]
A variable sized array of bytes
property DynamicBytes.native : Bytes
Section titled “property DynamicBytes.native : Bytes”Return the Bytes representation of the address after ARC-4 decoding
property DynamicBytes.length : UInt64
Section titled “property DynamicBytes.length : UInt64”Returns the current length of the array
DynamicBytes.append
Section titled “DynamicBytes.append”DynamicBytes.append(item: _TArrayItem, /) → None
Append an item to this array
DynamicBytes.extend
Section titled “DynamicBytes.extend”DynamicBytes.extend(other: Iterable[_TArrayItem], /) → None
Extend this array with the contents of another array
DynamicBytes.pop
Section titled “DynamicBytes.pop”DynamicBytes.pop() → _TArrayItem
Remove and return the last item of this array
DynamicBytes.copy
Section titled “DynamicBytes.copy”DynamicBytes.copy() → Self
Create a copy of this array
DynamicBytes.to_native
Section titled “DynamicBytes.to_native”DynamicBytes.to_native(element_type: type[_TNativeArrayItem], /) → Array[_TNativeArrayItem]
Convert to an algopy.Array with the specified element type.
Only allowed if the element type is compatible with this arrays element type e.g. arc4.UInt64 -> UInt64
classmethod DynamicBytes.from_log
Section titled “classmethod DynamicBytes.from_log”DynamicBytes.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
DynamicBytes.validate
Section titled “DynamicBytes.validate”DynamicBytes.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
class Tuple
Section titled “class Tuple”Tuple(items: tuple[Unpack[_TTuple]], /)
Bases: algopy.arc4._ABIEncoded, tuple[typing.Unpack[algopy.arc4._TTuple]]
An ARC-4 ABI tuple, containing other ARC-4 ABI types
Initialization
Section titled “Initialization”Construct an ARC-4 tuple from a native Python tuple
property Tuple.native : tuple[Unpack[_TTuple]]
Section titled “property Tuple.native : tuple[Unpack[_TTuple]]”Convert to a native Python tuple - note that the elements of the tuple should be considered to be copies of the original elements
Tuple.copy
Section titled “Tuple.copy”Tuple.copy() → Self
Create a copy of this tuple
classmethod Tuple.from_log
Section titled “classmethod Tuple.from_log”Tuple.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
Tuple.validate
Section titled “Tuple.validate”Tuple.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
Tuple.count
Section titled “Tuple.count”Tuple.count()
Return number of occurrences of value.
Tuple.index
Section titled “Tuple.index”Tuple.index()
Return first index of value.
Raises ValueError if the value is not present.
class Struct
Section titled “class Struct”Bases: algopy.arc4._ABIEncoded
Base class for ARC-4 Struct types
classmethod Struct.__init_subclass__
Section titled “classmethod Struct.__init_subclass__”Struct.__init_subclass__(*, frozen: bool = False, kw_only: bool = False)
Struct.copy
Section titled “Struct.copy”Struct.copy() → Self
Create a copy of this struct
classmethod Struct.from_log
Section titled “classmethod Struct.from_log”Struct.from_log(log: Bytes, /) → Self
Load an ABI type from application logs, checking for the ABI return prefix 0x151f7c75
Struct.validate
Section titled “Struct.validate”Struct.validate() → None
Performs validation to ensure the value is well-formed, errors if it is not
class ARC4Client
Section titled “class ARC4Client”Bases: typing.Protocol
Used to provide typed method signatures for ARC-4 contracts
abi_call
Section titled “abi_call”Provides a typesafe way of calling ARC-4 methods via an inner transaction
def abi_call( self, method: Callable[..., _TABIResult_co] | str, /, *args: object, 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
- app_id: Application to call, if 0 or not specified will create a new application
- on_completion: OnCompleteAction value for the transaction. If not specified will be inferred from Algorand Python method where possible
- approval_program: When creating or updating an application, the approval program
- clear_state_program: When creating or updating an application, the clear state program
- global_num_uint: When creating an application the number of global uints
- global_num_bytes: When creating an application the number of global bytes
- local_num_uint: When creating an application the number of local uints
- local_num_bytes: When creating an application the number of local bytes
- extra_program_pages: When creating an application the The number of extra program pages
- fee: The fee to pay for the transaction, defaults to 0
- sender: The sender address for the transaction
- note: Note to include with the transaction
- rekey_to: Account to rekey to
RETURNS:
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 methodresult, txn = abi_call(HelloWorldContract.hello, arc4.String("World"), app=...)assert result == "Hello, World"
# can reference a method selectorresult, 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 typeresult, txn = abi_call[arc4.String]("hello", "There", app=...)assert result == "Hello, There"
# calling a method without a return valuetxn = abi_call(HelloWorldContract.no_return, arc4.String("World"), app=...)arc4_create
Section titled “arc4_create”arc4_create(method: Callable[algopy.arc4._P, _TABIResult_co], /, *args: object, compiled: CompiledContract = …, on_completion: OnCompleteAction = …, fee: UInt64 | int = 0, sender: Account | str = …, note: Bytes | bytes | str = …, rekey_to: Account | str = …) → tuple[algopy.arc4._TABIResult_co, ApplicationCallInnerTransaction]
Provides a typesafe and convenient way of creating an ARC4Contract via an inner transaction
- Parameters:
- method – An ARC-4 create method (ABI or bare), or an ARC4Contract with a single create method
- args – ABI args for chosen method
- compiled – If supplied will be used to specify transaction parameters required for creation, can be omitted if template variables are not used
- on_completion – OnCompleteAction value for the transaction If not specified will be inferred from Algorand Python method where possible
- fee – The fee to pay for the transaction, defaults to 0
- sender – The sender address for the transaction
- note – Note to include with the transaction
- rekey_to – Account to rekey to
arc4_update
Section titled “arc4_update”arc4_update(method: Callable[algopy.arc4._P, _TABIResult_co], /, *args: object, app_id: Application | UInt64 | int, compiled: CompiledContract = …, fee: UInt64 | int = 0, sender: Account | str = …, note: Bytes | bytes | str = …, rekey_to: Account | str = …, reject_version: UInt64 | int = …) → tuple[algopy.arc4._TABIResult_co, ApplicationCallInnerTransaction]
Provides a typesafe and convenient way of updating an ARC4Contract via an inner transaction
- Parameters:
- method – An ARC-4 update method (ABI or bare), or an ARC4Contract with a single update method
- args – ABI args for chosen method
- app_id – Application to update
- compiled – If supplied will be used to specify transaction parameters required for updating, can be omitted if template variables are not used
- fee – The fee to pay for the transaction, defaults to 0
- sender – The sender address for the transaction
- note – Note to include with the transaction
- rekey_to – Account to rekey to
Emit an ARC-28 event for the provided event signature or name, and provided args.
- Parameters:
- event – Either an ARC-4 Struct, a native Struct, an event name, or event signature.
- If event is an ARC-4 Struct, the event signature will be determined from the Struct name and fields
- If event is a native Struct, its fields will be automatically converted to their ARC-4 equivalents
- 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 ARC-4 Tuple
- event – Either an ARC-4 Struct, a native Struct, an event name, or event signature.
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)encode
Section titled “encode”encode(value: object, /) → Bytes
Encode a value to ARC-4 bytes.
When given a native value, performs ARC-4 encoding. When given an already ARC-4 encoded value, reinterprets the underlying bytes.
decode
Section titled “decode”decode(typ: type[_TDecode], value: Bytes | bytes, /, *, validate: Literal[True, False] = True) → _TDecode
Decode ARC-4 encoded bytes to a value of the specified type.
- Parameters:
- typ – The target type to decode into.
- value – The ARC-4 encoded bytes to decode.
- validate – If True (default), validates the encoding of
valuebytes.