Create
Overview
Canisters contain both code and state. Once you have written the code for a canister, the canister doesn't exist until it is registered with ICP, either locally, on the playground, or on the mainnet.
Creating canisters
- Prerequisites
Canisters are created with dfx canister create
. They are initially empty and do not contain program code. The code must be compiled into Wasm and installed into the empty canister before it can be deployed.
Create your canisters from within the project's directory:
dfx canister create <canister-name>
: Create a canister locally. The local replica must be running to create a canister locally. Start it withdfx start --background
.dfx canister create <canister-name> --network=playground
: Create a canister on the playground. Creating a canister on the playground is free, but canisters are temporary and will be removed after 20 minutes.dfx canister create <canister-name> --network=ic
: Create a canister on the mainnet. Creating a canister on the mainnet will cost cycles.dfx canister create --all --network=ic
: Create all canisters in the project'sdfx.json
file on the mainnet.
Settings can be configured while creating a canister using optional flags. View the full list of settings.
When a canister is created, the following steps happen:
A canister ID is registered with the local replica or the mainnet for each canister in the project's
dfx.json
file.The following canister components are created:
- List of controllers.
- Cycles balance.
- Reserved cycles balance.
- Canister status.
- Resource reservations.
Each canister ID is returned in the command line.
Errors related to canister creation
Common errors related to canister creation include: