algokit_utils.applications.app_manager ====================================== .. py:module:: algokit_utils.applications.app_manager Attributes ---------- .. autoapisummary:: algokit_utils.applications.app_manager.UPDATABLE_TEMPLATE_NAME algokit_utils.applications.app_manager.DELETABLE_TEMPLATE_NAME Classes ------- .. autoapisummary:: algokit_utils.applications.app_manager.AppManager Module Contents --------------- .. py:data:: UPDATABLE_TEMPLATE_NAME :value: 'TMPL_UPDATABLE' The name of the TEAL template variable for deploy-time immutability control. .. py:data:: DELETABLE_TEMPLATE_NAME :value: 'TMPL_DELETABLE' The name of the TEAL template variable for deploy-time permanence control. .. py:class:: AppManager(algod_client: algosdk.v2client.algod.AlgodClient) A manager class for interacting with Algorand applications. Provides functionality for compiling TEAL code, managing application state, and interacting with application boxes. :param algod_client: The Algorand client instance to use for interacting with the network :example: >>> app_manager = AppManager(algod_client) .. py:method:: compile_teal(teal_code: str) -> algokit_utils.models.application.CompiledTeal Compile TEAL source code. :param teal_code: The TEAL source code to compile :return: The compiled TEAL code and associated metadata .. py:method:: compile_teal_template(teal_template_code: str, template_params: algokit_utils.models.state.TealTemplateParams | None = None, deployment_metadata: collections.abc.Mapping[str, bool | None] | None = None) -> algokit_utils.models.application.CompiledTeal Compile a TEAL template with parameters. :param teal_template_code: The TEAL template code to compile :param template_params: Parameters to substitute in the template :param deployment_metadata: Deployment control parameters :return: The compiled TEAL code and associated metadata :example: >>> app_manager = AppManager(algod_client) >>> teal_template_code = ... # This is a TEAL template ... # It can contain template variables like {TMPL_UPDATABLE} and {TMPL_DELETABLE} ... >>> compiled_teal = app_manager.compile_teal_template(teal_template_code) .. py:method:: get_compilation_result(teal_code: str) -> algokit_utils.models.application.CompiledTeal | None Get cached compilation result for TEAL code if available. :param teal_code: The TEAL source code :return: The cached compilation result if available, None otherwise :example: >>> app_manager = AppManager(algod_client) >>> teal_code = "RETURN 1" >>> compiled_teal = app_manager.compile_teal(teal_code) >>> compilation_result = app_manager.get_compilation_result(teal_code) .. py:method:: get_by_id(app_id: int) -> algokit_utils.models.application.AppInformation Get information about an application by ID. :param app_id: The application ID :return: Information about the application :example: >>> app_manager = AppManager(algod_client) >>> app_id = 1234567890 >>> app_info = app_manager.get_by_id(app_id) .. py:method:: get_global_state(app_id: int) -> dict[str, algokit_utils.models.application.AppState] Get the global state of an application. :param app_id: The application ID :return: The application's global state :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> global_state = app_manager.get_global_state(app_id) .. py:method:: get_local_state(app_id: int, address: str) -> dict[str, algokit_utils.models.application.AppState] Get the local state for an account in an application. :param app_id: The application ID :param address: The account address :return: The account's local state for the application :raises ValueError: If local state is not found :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> address = "SENDER_ADDRESS" >>> local_state = app_manager.get_local_state(app_id, address) .. py:method:: get_box_names(app_id: int) -> list[algokit_utils.models.state.BoxName] Get names of all boxes for an application. :param app_id: The application ID :return: List of box names :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> box_names = app_manager.get_box_names(app_id) .. py:method:: get_box_value(app_id: int, box_name: algokit_utils.models.state.BoxIdentifier) -> bytes Get the value stored in a box. :param app_id: The application ID :param box_name: The box identifier :return: The box value as bytes :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> box_name = "BOX_NAME" >>> box_value = app_manager.get_box_value(app_id, box_name) .. py:method:: get_box_values(app_id: int, box_names: list[algokit_utils.models.state.BoxIdentifier]) -> list[bytes] Get values for multiple boxes. :param app_id: The application ID :param box_names: List of box identifiers :return: List of box values as bytes :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> box_names = ["BOX_NAME_1", "BOX_NAME_2"] >>> box_values = app_manager.get_box_values(app_id, box_names) .. py:method:: get_box_value_from_abi_type(app_id: int, box_name: algokit_utils.models.state.BoxIdentifier, abi_type: algokit_utils.applications.abi.ABIType) -> algokit_utils.applications.abi.ABIValue Get and decode a box value using an ABI type. :param app_id: The application ID :param box_name: The box identifier :param abi_type: The ABI type to decode with :return: The decoded box value :raises ValueError: If decoding fails :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> box_name = "BOX_NAME" >>> abi_type = ABIType.UINT >>> box_value = app_manager.get_box_value_from_abi_type(app_id, box_name, abi_type) .. py:method:: get_box_values_from_abi_type(app_id: int, box_names: list[algokit_utils.models.state.BoxIdentifier], abi_type: algokit_utils.applications.abi.ABIType) -> list[algokit_utils.applications.abi.ABIValue] Get and decode multiple box values using an ABI type. :param app_id: The application ID :param box_names: List of box identifiers :param abi_type: The ABI type to decode with :return: List of decoded box values :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> box_names = ["BOX_NAME_1", "BOX_NAME_2"] >>> abi_type = ABIType.UINT >>> box_values = app_manager.get_box_values_from_abi_type(app_id, box_names, abi_type) .. py:method:: get_box_reference(box_id: algokit_utils.models.state.BoxIdentifier | algokit_utils.models.state.BoxReference) -> tuple[int, bytes] :staticmethod: Get standardized box reference from various identifier types. :param box_id: The box identifier :return: Tuple of (app_id, box_name_bytes) :raises ValueError: If box identifier type is invalid :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> box_name = "BOX_NAME" >>> box_reference = app_manager.get_box_reference(box_name) .. py:method:: get_abi_return(confirmation: algosdk.v2client.algod.AlgodResponseType, method: algosdk.abi.Method | None = None) -> algokit_utils.applications.abi.ABIReturn | None :staticmethod: Get the ABI return value from a transaction confirmation. :param confirmation: The transaction confirmation :param method: The ABI method :return: The parsed ABI return value, or None if not available :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> method = "METHOD_NAME" >>> confirmation = algod_client.pending_transaction_info(tx_id) >>> abi_return = app_manager.get_abi_return(confirmation, method) .. py:method:: decode_app_state(state: list[dict[str, Any]]) -> dict[str, algokit_utils.models.application.AppState] :staticmethod: Decode application state from raw format. :param state: The raw application state :return: Decoded application state :raises ValueError: If unknown state data type is encountered :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> state = app_manager.get_global_state(app_id) >>> decoded_state = app_manager.decode_app_state(state) .. py:method:: replace_template_variables(program: str, template_values: algokit_utils.models.state.TealTemplateParams) -> str :staticmethod: Replace template variables in TEAL code. :param program: The TEAL program code :param template_values: Template variable values to substitute :return: TEAL code with substituted values :raises ValueError: If template value type is unexpected :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> program = "RETURN 1" >>> template_values = {"TMPL_UPDATABLE": True, "TMPL_DELETABLE": True} >>> updated_program = app_manager.replace_template_variables(program, template_values) .. py:method:: replace_teal_template_deploy_time_control_params(teal_template_code: str, params: collections.abc.Mapping[str, bool | None]) -> str :staticmethod: Replace deploy-time control parameters in TEAL template. :param teal_template_code: The TEAL template code :param params: The deploy-time control parameters :return: TEAL code with substituted control parameters :raises ValueError: If template variables not found in code :example: >>> app_manager = AppManager(algod_client) >>> app_id = 123 >>> teal_template_code = "RETURN 1" >>> params = {"TMPL_UPDATABLE": True, "TMPL_DELETABLE": True} >>> updated_teal_code = app_manager.replace_teal_template_deploy_time_control_params( teal_template_code, params ) .. py:method:: strip_teal_comments(teal_code: str) -> str :staticmethod: Strip comments from TEAL code. :param teal_code: The TEAL code to strip comments from :return: The TEAL code with comments stripped :example: >>> app_manager = AppManager(algod_client) >>> teal_code = "RETURN 1" >>> stripped_teal_code = app_manager.strip_teal_comments(teal_code)