AppManager
@algorandfoundation/algokit-utils / types/app-manager / AppManager
types/app-manager.AppManager
Allows management of application information.
Table of contents
Constructors
Properties
Methods
- compileTeal
- compileTealTemplate
- getBoxNames
- getBoxValue
- getBoxValueFromABIType
- getBoxValues
- getBoxValuesFromABIType
- getById
- getCompilationResult
- getGlobalState
- getLocalState
- decodeAppState
- getABIReturn
- getBoxReference
- replaceTealTemplateDeployTimeControlParams
- replaceTealTemplateParams
- stripTealComments
Constructors
constructor
• new AppManager(algod
): AppManager
Creates an AppManager
Parameters
Name | Type | Description |
---|---|---|
algod | AlgodClient | An algod instance |
Returns
Defined in
Properties
_algod
• Private
_algod: AlgodClient
Defined in
_compilationResults
• Private
_compilationResults: Record
<string
, CompiledTeal
> = {}
Defined in
Methods
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
Name | Type | Description |
---|---|---|
tealCode | string | The TEAL code |
Returns
Promise
<CompiledTeal
>
The information about the compiled file
Example
const compiled = await appManager.compileTeal(tealProgram);
Defined in
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_UPDATABLE
for updatability / immutability controlTMPL_DELETABLE
for deletability / permanence control
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
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
getBoxNames
▸ getBoxNames(appId
): Promise
<BoxName
[]>
Returns the names of the current boxes for the given app.
Parameters
Name | Type | Description |
---|---|---|
appId | bigint | The ID of the app return box names for |
Returns
Promise
<BoxName
[]>
The current box names
Example
const boxNames = await appManager.getBoxNames(12353n);
Defined in
getBoxValue
▸ getBoxValue(appId
, boxName
): Promise
<Uint8Array
>
Returns the value of the given box name for the given app.
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
Promise
<Uint8Array
>
The current box value as a byte array
Example
const boxValue = await appManager.getBoxValue(12353n, 'boxName');
Defined in
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
Name | Type | Description |
---|---|---|
request | BoxValueRequestParams | The parameters for the box value request |
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
getBoxValues
▸ getBoxValues(appId
, boxNames
): Promise
<Uint8Array
[]>
Returns the value of the given box names for the given app.
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
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
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
Name | Type | Description |
---|---|---|
request | BoxValuesRequestParams | The parameters for the box value request |
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
getById
▸ getById(appId
): Promise
<AppInformation
>
Returns the current app information for the app with the given ID.
Parameters
Name | Type | Description |
---|---|---|
appId | bigint | The ID of the app |
Returns
Promise
<AppInformation
>
The app information
Example
const appInfo = await appManager.getById(12353n);
Defined in
getCompilationResult
▸ getCompilationResult(tealCode
): undefined
| CompiledTeal
Returns a previous compilation result.
Parameters
Name | Type | Description |
---|---|---|
tealCode | string | The TEAL code |
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
getGlobalState
▸ getGlobalState(appId
): Promise
<AppState
>
Returns the current global state values for the given app ID and account address
Parameters
Name | Type | Description |
---|---|---|
appId | bigint | The ID of the app to return global state for |
Returns
Promise
<AppState
>
The current global state for the given app
Example
const globalState = await appManager.getGlobalState(12353n);
Defined in
getLocalState
▸ getLocalState(appId
, address
): Promise
<AppState
>
Returns the current local state values for the given app ID and account address
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
Promise
<AppState
>
The current local state for the given (app, account) combination
Example
const localState = await appManager.getLocalState(12353n, 'ACCOUNTADDRESS');
Defined in
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
Name | Type | Description |
---|---|---|
state | { key : Uint8Array ; value : TealValue | EvalDelta }[] | A global-state , local-state , global-state-deltas or local-state-deltas |
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
getABIReturn
▸ getABIReturn(confirmation
, method
): undefined
| ABIReturn
Returns any ABI return values for the given app call arguments and transaction confirmation.
Parameters
Name | Type | Description |
---|---|---|
confirmation | undefined | PendingTransactionResponse | The transaction confirmation from algod |
method | undefined | ABIMethod | The ABI method |
Returns
undefined
| ABIReturn
The return value for the method call
Example
const returnValue = AppManager.getABIReturn( confirmation, ABIMethod.fromSignature('hello(string)void'),);
Defined in
getBoxReference
▸ getBoxReference(boxId
): BoxReference
Returns a algosdk.BoxReference
given a BoxIdentifier
or BoxReference
.
Parameters
Name | Type | Description |
---|---|---|
boxId | BoxIdentifier | BoxReference | The box to return a reference for |
Returns
BoxReference
The box reference ready to pass into a algosdk.Transaction
Example
const boxRef = AppManager.getBoxReference('boxName');
Defined in
replaceTealTemplateDeployTimeControlParams
▸ replaceTealTemplateDeployTimeControlParams(tealTemplateCode
, params
): string
Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.
TMPL_UPDATABLE
for updatability / immutability controlTMPL_DELETABLE
for 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
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
string
The replaced TEAL code
Example
const tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealTemplate, { updatable: true, deletable: false,});
Defined in
replaceTealTemplateParams
▸ replaceTealTemplateParams(tealTemplateCode
, templateParams?
): string
Performs template substitution of a teal file.
Looks for TMPL_{parameter}
for template replacements.
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
string
The TEAL code with replacements
Example
const tealCode = AppManager.replaceTealTemplateParams(tealTemplate, { TMPL_APP_ID: 12345n });
Defined in
stripTealComments
▸ stripTealComments(tealCode
): string
Remove comments from TEAL code (useful to reduce code size before compilation).
Parameters
Name | Type | Description |
---|---|---|
tealCode | string | The TEAL logic to strip |
Returns
string
The TEAL without comments
Example
const stripped = AppManager.stripTealComments(tealProgram);