Canister lifecycle
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.
Learn more about writing canister code.
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.
Learn more about creating canisters.
Compile
Once an empty canister has been created, the canister's code must be compiled into a Wasm binary.
Learn more about compiling code into Wasm.
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.
Deploy
Once a canister has an installed Wasm binary, it can be deployed to the local, testnet, or mainnet environments.
Learn more about deploying canisters.
Call
After deployment, 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.
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.
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.