Skip to main content

Canister lifecycle

Beginner
Concept

Write

The ICP accepts and executes canister code in the WebAssembly (Wasm) binary format. Usually, developers write code in a higher-level language and then compile the code into a Wasm binary that can be deployed into a canister.

Deploy

Create

A developer can create an empty canister on ICP by calling the system canister. It can be done using the NNS frontend dapp in the browser or dfx in the command line. The developer can specify the initial canister settings and choose the target subnet. Once the canister is created, the developer gets its canister ID and becomes the controller of the canister.

Create canister

Install

The next step after writing the code and creating a canister is installing the code into the canister. This can be done by calling the install_code endpoint of the system canister and passing the canister ID and the Wasm binary to it. The dfx tool has a command for making this call.

Install canister

Call

After installation, the canister accepts and processes messages (calls) from users and other canisters. Only the public endpoints of the canister can be called. These endpoints correspond to exported Wasm functions that are annotated with canister_update or canister_query in their names.

Call canister

Maintain

Certain system operations that change the state of the canister can be performed only by the controllers of the canister. The most important operation is upgrading the canister by installing a different Wasm binary. In the initial stages of development, the canister is usually controlled by its developer, which allows the developer to iterate quickly. As the canister becomes mature and production ready, the control over it could move to a DAO in order to make the canister secure and trustworthy. Learn more about different types of controllers.

Manage canister

Since ICP uses a reverse gas model, the canister pays for its execution, storage, and other operations with cycles. This means that controllers and/or users of the canister have to ensure that the canister does not run out of cycles. If the canister runs out of cycles, it will be uninstalled by removing its Wasm binary and its storage.

If the canister is no longer used or needed, a controller of the canister can delete it. ICP guarantees that the canister ID will not be reused for another canister.