Skip to content

AppManager

@algorandfoundation/algokit-utils / types/app-manager / AppManager

types/app-manager.AppManager

Allows management of application information.

new AppManager(algod): AppManager

Creates an AppManager

NameTypeDescription
algodAlgodClientAn algod instance

AppManager

src/types/app-manager.ts:106

Private _algod: AlgodClient

src/types/app-manager.ts:99


Private _compilationResults: Record<string, CompiledTeal> = {}

src/types/app-manager.ts:100

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.

NameTypeDescription
tealCodestringThe TEAL code

Promise<CompiledTeal>

The information about the compiled file

Example

const compiled = await appManager.compileTeal(tealProgram);

src/types/app-manager.ts:125


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 control
  • TMPL_DELETABLE for deletability / permanence control
NameTypeDescription
tealTemplateCodestringThe TEAL logic to compile
templateParams?TealTemplateParamsAny parameters to replace in the .teal file before compiling
deploymentMetadata?ObjectThe deployment metadata the app will be deployed with
deploymentMetadata.deletable?boolean-
deploymentMetadata.updatable?boolean-

Promise<CompiledTeal>

The information about the compiled code

Example

const compiled = await appManager.compileTealTemplate(
tealTemplate,
{ TMPL_APP_ID: 12345n },
{ updatable: true, deletable: false },
);

src/types/app-manager.ts:161


getBoxNames(appId): Promise<BoxName[]>

Returns the names of the current boxes for the given app.

NameTypeDescription
appIdbigintThe ID of the app return box names for

Promise<BoxName[]>

The current box names

Example

const boxNames = await appManager.getBoxNames(12353n);

src/types/app-manager.ts:263


getBoxValue(appId, boxName): Promise<Uint8Array>

Returns the value of the given box name for the given app.

NameTypeDescription
appIdbigintThe ID of the app return box names for
boxNameBoxName | BoxIdentifierThe name of the box to return either as a string, binary array or BoxName

Promise<Uint8Array>

The current box value as a byte array

Example

const boxValue = await appManager.getBoxValue(12353n, 'boxName');

src/types/app-manager.ts:284


getBoxValueFromABIType(request): Promise<ABIValue>

Returns the value of the given box name for the given app decoded based on the given ABI type.

NameTypeDescription
requestBoxValueRequestParamsThe parameters for the box value request

Promise<ABIValue>

The current box value as an ABI value

Example

const boxValue = await appManager.getBoxValueFromABIType({
appId: 12353n,
boxName: 'boxName',
type: new ABIUintType(32),
});

src/types/app-manager.ts:314


getBoxValues(appId, boxNames): Promise<Uint8Array[]>

Returns the value of the given box names for the given app.

NameTypeDescription
appIdbigintThe 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

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']);

src/types/app-manager.ts:301


getBoxValuesFromABIType(request): Promise<ABIValue[]>

Returns the value of the given box names for the given app decoded based on the given ABI type.

NameTypeDescription
requestBoxValuesRequestParamsThe parameters for the box value request

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),
});

src/types/app-manager.ts:329


getById(appId): Promise<AppInformation>

Returns the current app information for the app with the given ID.

NameTypeDescription
appIdbigintThe ID of the app

Promise<AppInformation>

The app information

Example

const appInfo = await appManager.getById(12353n);

src/types/app-manager.ts:202


getCompilationResult(tealCode): undefined | CompiledTeal

Returns a previous compilation result.

NameTypeDescription
tealCodestringThe TEAL code

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);

src/types/app-manager.ts:187


getGlobalState(appId): Promise<AppState>

Returns the current global state values for the given app ID and account address

NameTypeDescription
appIdbigintThe ID of the app to return global state for

Promise<AppState>

The current global state for the given app

Example

const globalState = await appManager.getGlobalState(12353n);

src/types/app-manager.ts:229


getLocalState(appId, address): Promise<AppState>

Returns the current local state values for the given app ID and account address

NameTypeDescription
appIdbigintThe ID of the app to return local state for
addressstring | AddressThe string address of the account to get local state for the given app

Promise<AppState>

The current local state for the given (app, account) combination

Example

const localState = await appManager.getLocalState(12353n, 'ACCOUNTADDRESS');

src/types/app-manager.ts:244


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.

NameTypeDescription
state{ key: Uint8Array ; value: TealValue | EvalDelta }[]A global-state, local-state, global-state-deltas or local-state-deltas

AppState

An object keyeed by the UTF-8 representation of the key with various parsings of the values

Example

const stateValues = AppManager.decodeAppState(state);

src/types/app-manager.ts:361


getABIReturn(confirmation, method): undefined | ABIReturn

Returns any ABI return values for the given app call arguments and transaction confirmation.

NameTypeDescription
confirmationundefined | PendingTransactionResponseThe transaction confirmation from algod
methodundefined | ABIMethodThe ABI method

undefined | ABIReturn

The return value for the method call

Example

const returnValue = AppManager.getABIReturn(
confirmation,
ABIMethod.fromSignature('hello(string)void'),
);

src/types/app-manager.ts:414


getBoxReference(boxId): BoxReference

Returns a algosdk.BoxReference given a BoxIdentifier or BoxReference.

NameTypeDescription
boxIdBoxIdentifier | BoxReferenceThe box to return a reference for

BoxReference

The box reference ready to pass into a algosdk.Transaction

Example

const boxRef = AppManager.getBoxReference('boxName');

src/types/app-manager.ts:343


replaceTealTemplateDeployTimeControlParams

Section titled “replaceTealTemplateDeployTimeControlParams”

replaceTealTemplateDeployTimeControlParams(tealTemplateCode, params): string

Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.

  • TMPL_UPDATABLE for updatability / immutability control
  • TMPL_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.

NameTypeDescription
tealTemplateCodestringThe TEAL template code to substitute
paramsObjectThe deploy-time deployment control parameter value to replace
params.deletable?boolean-
params.updatable?boolean-

string

The replaced TEAL code

Example

const tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealTemplate, {
updatable: true,
deletable: false,
});

src/types/app-manager.ts:448


replaceTealTemplateParams(tealTemplateCode, templateParams?): string

Performs template substitution of a teal file.

Looks for TMPL_{parameter} for template replacements.

NameTypeDescription
tealTemplateCodestringThe TEAL template code to make parameter replacements in
templateParams?TealTemplateParamsAny parameters to replace in the teal code

string

The TEAL code with replacements

Example

const tealCode = AppManager.replaceTealTemplateParams(tealTemplate, { TMPL_APP_ID: 12345n });

src/types/app-manager.ts:483


stripTealComments(tealCode): string

Remove comments from TEAL code (useful to reduce code size before compilation).

NameTypeDescription
tealCodestringThe TEAL logic to strip

string

The TEAL without comments

Example

const stripped = AppManager.stripTealComments(tealProgram);

src/types/app-manager.ts:522