The Building Block of ICP: Canister
A canister is the fundamental computational unit of the Internet Computer. It combines both code and state into a single smart contract-like unit that runs on the ICP blockchain.
A canister can expose public methods, receive messages, store persistent data, communicate with other canisters and serve web content. This allows developers to build full-stack decentralized applications without depending entirely on traditional cloud hosting.
Code + State
Each canister bundles compiled WebAssembly code with persistent state.
Autonomous
Canisters operate independently and respond to messages from users or other canisters.
Interoperable
Canisters communicate through message passing to form larger applications.
- ✓Scalable: canisters run on ICP subnet infrastructure and are designed for internet-scale services.
- ✓Upgradable: developers can upgrade code while preserving important state when upgrade hooks are handled correctly.
- ✓Composable: multiple canisters can work together as one dApp.
- ✓Web-ready: frontend assets and backend logic can both be deployed as canisters.
Cycles: The Fuel of ICP Canisters
Cycles are used to pay for canister execution and resource consumption. They are similar to gas in Ethereum, but ICP uses a reverse-gas style model: developers fund the canister, and users can interact with the application without directly paying a transaction fee for every call.
Computation
Instructions executed by canisters consume cycles.
Storage
Data stored in heap or stable memory costs cycles over time.
Network
Messages and network operations also consume cycles.
Cycles make ICP applications feel more like web services: the canister is funded by the developer or operator, not every end user.
The original article explains that ICP tokens can be converted into cycles and that cycles are stored within canisters. When a canister runs out of cycles, it cannot continue serving requests until it is refueled.
Creating a Cycle Wallet in a Local Network
For local development, start a clean local replica, create or retrieve a local cycle wallet, and check the wallet balance. Use normal double hyphens in your terminal commands.
dfx start --background --cleandfx identity get-walletdfx wallet balancedfx version and command help because wallet and cycles workflows may evolve between SDK releases.Motoko: The Native Programming Language of ICP
Motoko is designed for writing canister smart contracts on the Internet Computer. It supports the actor-based programming model used by ICP and compiles to WebAssembly.
Actor Model
Motoko canisters are actors with private state and public methods.
Type Safe
Strong typing helps prevent many common programming mistakes.
WebAssembly
Motoko compiles to Wasm, which runs efficiently in ICP canisters.
Memory Management
Motoko provides automatic memory management and supports persistent application state.
Async Messages
It supports asynchronous calls between canisters and external users.
Interoperability
ICP also supports canisters written in Rust and other Wasm-compatible languages through CDKs.
Create a Hello World Project
To create and deploy canisters, start the local network, create a project, choose a backend language and select a frontend option. The original chapter uses Motoko for the backend and React for the frontend.
dfx start --backgrounddfx new helloDuring project creation, choose a backend language such as Motoko, Rust, Python or TypeScript, depending on the options offered by your installed SDK. For this chapter, choose Motoko. Then choose a frontend framework such as React and optionally add Internet Identity.
dfx new helloTypical Project Structure
| File or Folder | Purpose |
|---|---|
dfx.json | Defines canisters, networks and project configuration. |
src/hello_backend | Contains backend canister code, such as Motoko source files. |
src/hello_frontend | Contains frontend application code and assets. |
package.json | Lists frontend dependencies and scripts for JavaScript-based tooling. |
Deploying Canisters on the Local Network
After creating the project, go into the project folder and deploy the canisters locally. The dfx deploy command registers, builds and installs canisters defined in dfx.json.
cd hellodfx deployIf the deployment is successful, the terminal will show local canister IDs and frontend URLs. Open the frontend URL in your browser to test the application.
Create
dfx creates the canisters defined in the project configuration.
Build
Backend code is compiled and frontend assets are prepared.
Install
The compiled canister code is installed into the local replica.
Deploying Canisters on the IC Mainnet
To deploy on the Internet Computer mainnet, use the --network ic option. The official dfx deploy command also supports --ic as an alias for mainnet deployment.
dfx deploy --network icIf the deployment succeeds, the output will show backend and frontend canister URLs. The frontend can be accessed from desktop and mobile browsers without registering a traditional domain or hosting the app on a centralized web server.
dfx canister --network ic status <canister_id>dfx canister id <canister_name> --network icObtaining Cycles
You need cycles to deploy and operate ICP canisters on the mainnet. The original article describes two methods: redeeming a cycles coupon and converting ICP tokens into cycles.
Method 1: Redeem a Faucet Coupon
dfx cycles redeem-faucet-coupon --network ic <COUPON_CODE>dfx cycles --network ic balanceMethod 2: Convert ICP Tokens to Cycles
dfx identity get-principaldfx ledger --ic create-canister <principal-identifier> --amount <ICP_AMOUNT>dfx version before moving ICP or topping up cycles.Appendix: Useful dfx Commands
Identity
dfx identity list
dfx identity whoami
dfx identity use <identity_name>
dfx identity get-principal
dfx identity remove <identity_name>Ledger and Balance
dfx ledger balance
dfx cycles --network ic balanceCanister Status
dfx canister --network ic status <canister_id>
dfx canister --network ic info <canister_id>
dfx canister id <canister_name> --network icCycles Top Up
dfx ledger --network ic top-up <wallet_or_canister_id> --amount <ICP_AMOUNT>
dfx canister --network ic deposit-cycles <amount> <canister_name>dfx stopDeveloper Tips and Common Mistakes
- ✓Use proper double hyphens such as
--network ic; copied web pages sometimes convert hyphens into long dashes. - ✓Confirm the active identity with
dfx identity whoamibefore deploying to mainnet. - ✓Keep enough cycles in the canister before running a live application.
- ✓Do local deployments before deploying to the Internet Computer mainnet.
- ✓Read
dfx.jsonbecause it defines the canisters thatdfx deploywill build and deploy. - ✓Upgrade carefully when canisters store important state. Test upgrade paths before production deployment.
The best ICP workflow is simple: build locally, test locally, check identity and cycles, then deploy to mainnet only when ready.
Summary
- ✓A canister is the core compute unit of ICP, combining WebAssembly code and persistent state.
- ✓Cycles pay for computation, storage and network resources used by canisters.
- ✓Motoko is a native ICP programming language designed around the actor model.
- ✓
dfx new hellocreates a project, anddfx deploydeploys canisters locally. - ✓
dfx deploy --network icdeploys to the Internet Computer mainnet and consumes real cycles. - ✓Useful commands include identity management, cycles balance, canister status and top-up commands.