Skip to content

Commit df9f82d

Browse files
authored
docs: more examples for deploy time immutability control (#380)
1 parent f09cd80 commit df9f82d

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

docs/capabilities/app-deploy.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ In order for a smart contract to opt-in to use this functionality, it must have
245245
- `TMPL_UPDATABLE` - Which will be replaced with a `1` if an app should be updatable and `0` if it shouldn't (immutable)
246246
- `TMPL_DELETABLE` - Which will be replaced with a `1` if an app should be deletable and `0` if it shouldn't (permanent)
247247

248-
If you are building a smart contract using the production [AlgoKit init templates](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/init.md) provide a reference implementation out of the box for the deploy-time immutability and permanence control.
249-
250248
If you passed in a TEAL template for the approvalProgram or clearStateProgram (i.e. a `string` rather than a `Uint8Array`) then `deploy` will return the [compilation result](../code/interfaces/types_app.CompiledTeal.md) of substituting then compiling the TEAL template(s) in the following properties of the return value:
251249

252250
- `compiledApproval?: CompiledTeal`
@@ -259,6 +257,48 @@ Template substitution is done by executing `algorand.app.compileTealTemplate(tea
259257
- `AppManager.replaceTealTemplateDeployTimeControlParams(tealTemplateCode, deploymentMetadata)` - If `deploymentMetadata` is provided, it allows for deploy-time immutability and permanence control by replacing `TMPL_UPDATABLE` with `deploymentMetadata.updatable` if it's not `undefined` and replacing `TMPL_DELETABLE` with `deploymentMetadata.deletable` if it's not `undefined`
260258
- `algorand.app.compileTeal(tealCode)` - Sends the final TEAL to algod for compilation and returns the result including the source map and caches the compilation result within the `AppManager` instance
261259

260+
#### Making updatable/deletable apps
261+
262+
Below is a sample in [Algorand Python SDK](https://github.com/algorandfoundation/puya) that demonstrates how to make an app updatable/deletable smart contract with the use of `TMPL_UPDATABLE` and `TMPL_DELETABLE` template parameters.
263+
264+
```python
265+
# ... your contract code ...
266+
@arc4.baremethod(allow_actions=["UpdateApplication"])
267+
def update(self) -> None:
268+
assert TemplateVar[bool]("UPDATABLE")
269+
270+
@arc4.baremethod(allow_actions=["DeleteApplication"])
271+
def delete(self) -> None:
272+
assert TemplateVar[bool]("DELETABLE")
273+
# ... your contract code ...
274+
```
275+
276+
Alternative example in [Algorand TypeScript SDK](https://github.com/algorandfoundation/puya-ts):
277+
278+
```typescript
279+
// ... your contract code ...
280+
@baremethod({ allowActions: 'UpdateApplication' })
281+
public onUpdate() {
282+
assert(TemplateVar<boolean>('UPDATABLE'))
283+
}
284+
285+
@baremethod({ allowActions: 'DeleteApplication' })
286+
public onDelete() {
287+
assert(TemplateVar<boolean>('DELETABLE'))
288+
}
289+
// ... your contract code ...
290+
```
291+
292+
With the above code, when deploying your application, you can pass in the following deploy-time parameters:
293+
294+
```typescript
295+
myFactory.deploy({
296+
... // other deployment parameters
297+
updatable: true, // resulting app will be updatable, and this metadata will be set in the ARC-2 transaction note
298+
deletable: false, // resulting app will not be deletable, and this metadata will be set in the ARC-2 transaction note
299+
})
300+
```
301+
262302
### Return value
263303

264304
When `deploy` executes it will return a [comprehensive result](../code/modules/types_app_deployer.md#appdeployresult) object that describes exactly what it did and has comprehensive metadata to describe the end result of the deployed app.

0 commit comments

Comments
 (0)