AppManager
@algorandfoundation/algokit-utils / types/app-manager / AppManager
types/app-manager.AppManager
Allows management of application information.
Table of contents
Section titled “Table of contents”Constructors
Section titled “Constructors”Properties
Section titled “Properties”Methods
Section titled “Methods”- compileTeal
- compileTealTemplate
- getBoxNames
- getBoxValue
- getBoxValueFromABIType
- getBoxValues
- getBoxValuesFromABIType
- getById
- getCompilationResult
- getGlobalState
- getLocalState
- decodeAppState
- getABIReturn
- getBoxReference
- replaceTealTemplateDeployTimeControlParams
- replaceTealTemplateParams
- stripTealComments
Constructors
Section titled “Constructors”constructor
Section titled “constructor”• new AppManager(algod): AppManager
Creates an AppManager
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
algod | AlgodClient | An algod instance |
Returns
Section titled “Returns”Defined in
Section titled “Defined in”Properties
Section titled “Properties”_algod
Section titled “_algod”• Private _algod: AlgodClient
Defined in
Section titled “Defined in”_compilationResults
Section titled “_compilationResults”• Private _compilationResults: Record<string, CompiledTeal> = {}
Defined in
Section titled “Defined in”Methods
Section titled “Methods”compileTeal
Section titled “compileTeal”▸ compileTeal(tealCode): Promise<CompiledTeal>
Compiles the given TEAL using algod and returns the result, including source map.
The result of this compilation is also cached keyed by the TEAL
code so it can be retrieved via getCompilationResult.
This function is re-entrant; it will only compile the same code once.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
tealCode | string | The TEAL code |
Returns
Section titled “Returns”Promise<CompiledTeal>
The information about the compiled file
Example
const compiled = await appManager.compileTeal(tealProgram);Defined in
Section titled “Defined in”compileTealTemplate
Section titled “compileTealTemplate”▸ compileTealTemplate(tealTemplateCode, templateParams?, deploymentMetadata?): Promise<CompiledTeal>
Performs template substitution of a teal template and compiles it, returning the compiled result.
Looks for TMPL_{parameter} for template replacements and replaces AlgoKit deploy-time control parameters
if deployment metadata is specified.
TMPL_UPDATABLEfor updatability / immutability controlTMPL_DELETABLEfor deletability / permanence control
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
tealTemplateCode | string | The TEAL logic to compile |
templateParams? | TealTemplateParams | Any parameters to replace in the .teal file before compiling |
deploymentMetadata? | Object | The deployment metadata the app will be deployed with |
deploymentMetadata.deletable? | boolean | - |
deploymentMetadata.updatable? | boolean | - |
Returns
Section titled “Returns”Promise<CompiledTeal>
The information about the compiled code
Example
const compiled = await appManager.compileTealTemplate( tealTemplate, { TMPL_APP_ID: 12345n }, { updatable: true, deletable: false },);Defined in
Section titled “Defined in”getBoxNames
Section titled “getBoxNames”▸ getBoxNames(appId): Promise<BoxName[]>
Returns the names of the current boxes for the given app.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
appId | bigint | The ID of the app return box names for |
Returns
Section titled “Returns”Promise<BoxName[]>
The current box names
Example
const boxNames = await appManager.getBoxNames(12353n);Defined in
Section titled “Defined in”getBoxValue
Section titled “getBoxValue”▸ getBoxValue(appId, boxName): Promise<Uint8Array>
Returns the value of the given box name for the given app.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
appId | bigint | The ID of the app return box names for |
boxName | BoxName | BoxIdentifier | The name of the box to return either as a string, binary array or BoxName |
Returns
Section titled “Returns”Promise<Uint8Array>
The current box value as a byte array
Example
const boxValue = await appManager.getBoxValue(12353n, 'boxName');Defined in
Section titled “Defined in”getBoxValueFromABIType
Section titled “getBoxValueFromABIType”▸ getBoxValueFromABIType(request): Promise<ABIValue>
Returns the value of the given box name for the given app decoded based on the given ABI type.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
request | BoxValueRequestParams | The parameters for the box value request |
Returns
Section titled “Returns”Promise<ABIValue>
The current box value as an ABI value
Example
const boxValue = await appManager.getBoxValueFromABIType({ appId: 12353n, boxName: 'boxName', type: new ABIUintType(32),});Defined in
Section titled “Defined in”getBoxValues
Section titled “getBoxValues”▸ getBoxValues(appId, boxNames): Promise<Uint8Array[]>
Returns the value of the given box names for the given app.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
appId | bigint | The ID of the app return box names for |
boxNames | (BoxName | BoxIdentifier)[] | The names of the boxes to return either as a string, binary array or BoxName |
Returns
Section titled “Returns”Promise<Uint8Array[]>
The current box values as a byte array in the same order as the passed in box names
Example
const boxValues = await appManager.getBoxValues(12353n, ['boxName1', 'boxName2']);Defined in
Section titled “Defined in”getBoxValuesFromABIType
Section titled “getBoxValuesFromABIType”▸ getBoxValuesFromABIType(request): Promise<ABIValue[]>
Returns the value of the given box names for the given app decoded based on the given ABI type.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
request | BoxValuesRequestParams | The parameters for the box value request |
Returns
Section titled “Returns”Promise<ABIValue[]>
The current box values as an ABI value in the same order as the passed in box names
Example
const boxValues = await appManager.getBoxValuesFromABIType({ appId: 12353n, boxNames: ['boxName1', 'boxName2'], type: new ABIUintType(32),});Defined in
Section titled “Defined in”getById
Section titled “getById”▸ getById(appId): Promise<AppInformation>
Returns the current app information for the app with the given ID.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
appId | bigint | The ID of the app |
Returns
Section titled “Returns”Promise<AppInformation>
The app information
Example
const appInfo = await appManager.getById(12353n);Defined in
Section titled “Defined in”getCompilationResult
Section titled “getCompilationResult”▸ getCompilationResult(tealCode): undefined | CompiledTeal
Returns a previous compilation result.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
tealCode | string | The TEAL code |
Returns
Section titled “Returns”undefined | CompiledTeal
The information about the previously compiled file
or undefined if that TEAL code wasn’t previously compiled
Example
const compiled = appManager.getCompilationResult(tealProgram);Defined in
Section titled “Defined in”getGlobalState
Section titled “getGlobalState”▸ getGlobalState(appId): Promise<AppState>
Returns the current global state values for the given app ID and account address
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
appId | bigint | The ID of the app to return global state for |
Returns
Section titled “Returns”Promise<AppState>
The current global state for the given app
Example
const globalState = await appManager.getGlobalState(12353n);Defined in
Section titled “Defined in”getLocalState
Section titled “getLocalState”▸ getLocalState(appId, address): Promise<AppState>
Returns the current local state values for the given app ID and account address
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
appId | bigint | The ID of the app to return local state for |
address | string | Address | The string address of the account to get local state for the given app |
Returns
Section titled “Returns”Promise<AppState>
The current local state for the given (app, account) combination
Example
const localState = await appManager.getLocalState(12353n, 'ACCOUNTADDRESS');Defined in
Section titled “Defined in”decodeAppState
Section titled “decodeAppState”▸ decodeAppState(state): AppState
Converts an array of global/local state values from the algod api to a more friendly generic object keyed by the UTF-8 value of the key.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
state | { key: Uint8Array ; value: TealValue | EvalDelta }[] | A global-state, local-state, global-state-deltas or local-state-deltas |
Returns
Section titled “Returns”An object keyeed by the UTF-8 representation of the key with various parsings of the values
Example
const stateValues = AppManager.decodeAppState(state);Defined in
Section titled “Defined in”getABIReturn
Section titled “getABIReturn”▸ getABIReturn(confirmation, method): undefined | ABIReturn
Returns any ABI return values for the given app call arguments and transaction confirmation.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
confirmation | undefined | PendingTransactionResponse | The transaction confirmation from algod |
method | undefined | ABIMethod | The ABI method |
Returns
Section titled “Returns”undefined | ABIReturn
The return value for the method call
Example
const returnValue = AppManager.getABIReturn( confirmation, ABIMethod.fromSignature('hello(string)void'),);Defined in
Section titled “Defined in”getBoxReference
Section titled “getBoxReference”▸ getBoxReference(boxId): BoxReference
Returns a algosdk.BoxReference given a BoxIdentifier or BoxReference.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
boxId | BoxIdentifier | BoxReference | The box to return a reference for |
Returns
Section titled “Returns”BoxReference
The box reference ready to pass into a algosdk.Transaction
Example
const boxRef = AppManager.getBoxReference('boxName');Defined in
Section titled “Defined in”replaceTealTemplateDeployTimeControlParams
Section titled “replaceTealTemplateDeployTimeControlParams”▸ replaceTealTemplateDeployTimeControlParams(tealTemplateCode, params): string
Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.
TMPL_UPDATABLEfor updatability / immutability controlTMPL_DELETABLEfor deletability / permanence control
Note: If these values are defined, but the corresponding TMPL_* value
isn’t in the teal code it will throw an exception.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
tealTemplateCode | string | The TEAL template code to substitute |
params | Object | The deploy-time deployment control parameter value to replace |
params.deletable? | boolean | - |
params.updatable? | boolean | - |
Returns
Section titled “Returns”string
The replaced TEAL code
Example
const tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealTemplate, { updatable: true, deletable: false,});Defined in
Section titled “Defined in”replaceTealTemplateParams
Section titled “replaceTealTemplateParams”▸ replaceTealTemplateParams(tealTemplateCode, templateParams?): string
Performs template substitution of a teal file.
Looks for TMPL_{parameter} for template replacements.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
tealTemplateCode | string | The TEAL template code to make parameter replacements in |
templateParams? | TealTemplateParams | Any parameters to replace in the teal code |
Returns
Section titled “Returns”string
The TEAL code with replacements
Example
const tealCode = AppManager.replaceTealTemplateParams(tealTemplate, { TMPL_APP_ID: 12345n });Defined in
Section titled “Defined in”stripTealComments
Section titled “stripTealComments”▸ stripTealComments(tealCode): string
Remove comments from TEAL code (useful to reduce code size before compilation).
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
tealCode | string | The TEAL logic to strip |
Returns
Section titled “Returns”string
The TEAL without comments
Example
const stripped = AppManager.stripTealComments(tealProgram);