ICP • Canisters • Cycles • Motoko • dfx

ICP Developer Guide — Chapter 2

Learn the building blocks of Internet Computer development: canisters, cycles, cycle wallets, Motoko, local deployment, mainnet deployment and essential dfx commands.

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.

Simple idea: a canister is like an advanced smart contract that stores code, state and application logic on the Internet Computer.
C

Code + State

Each canister bundles compiled WebAssembly code with persistent state.

A

Autonomous

Canisters operate independently and respond to messages from users or other canisters.

I

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.

CPU

Computation

Instructions executed by canisters consume cycles.

DB

Storage

Data stored in heap or stable memory costs cycles over time.

NET

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.

Start a Clean Local ICP Network
dfx start --background --clean
Create or Get the Local Cycle Wallet
dfx identity get-wallet
Check Wallet Balance
dfx wallet balance
Developer note: Always check your installed dfx 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.

A

Actor Model

Motoko canisters are actors with private state and public methods.

T

Type Safe

Strong typing helps prevent many common programming mistakes.

W

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.

Start Local Network
dfx start --background
Create a New Project
dfx new hello

During 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.

Run dfx new hello
Select backend language: Motoko
Select frontend framework: React
Add optional feature: Internet Identity
Review generated project files

Typical Project Structure

File or FolderPurpose
dfx.jsonDefines canisters, networks and project configuration.
src/hello_backendContains backend canister code, such as Motoko source files.
src/hello_frontendContains frontend application code and assets.
package.jsonLists 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.

Go to the Project Folder
cd hello
Deploy Locally
dfx deploy

If 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.

1

Create

dfx creates the canisters defined in the project configuration.

2

Build

Backend code is compiled and frontend assets are prepared.

3

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.

Deploy to the Internet Computer Mainnet
dfx deploy --network ic

If 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.

Mainnet deployment consumes real cycles. Before deploying, confirm your identity, canister IDs, cycles balance and project configuration.
Check Canister Status
dfx canister --network ic status <canister_id>
Get Mainnet Canister ID
dfx canister id <canister_name> --network ic

Obtaining 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

Redeem Cycles Coupon
dfx cycles redeem-faucet-coupon --network ic <COUPON_CODE>
Check Cycles Balance
dfx cycles --network ic balance

Method 2: Convert ICP Tokens to Cycles

Get Principal
dfx identity get-principal
Create Canister Using ICP
dfx ledger --ic create-canister <principal-identifier> --amount <ICP_AMOUNT>
Practical note: For current production workflows, check the latest ICP documentation and your dfx version before moving ICP or topping up cycles.

Appendix: Useful dfx Commands

Identity

Identity Commands
dfx identity list
dfx identity whoami
dfx identity use <identity_name>
dfx identity get-principal
dfx identity remove <identity_name>

Ledger and Balance

Ledger Commands
dfx ledger balance
dfx cycles --network ic balance

Canister Status

Canister Info
dfx canister --network ic status <canister_id>
dfx canister --network ic info <canister_id>
dfx canister id <canister_name> --network ic

Cycles Top Up

Top Up Commands
dfx ledger --network ic top-up <wallet_or_canister_id> --amount <ICP_AMOUNT>
dfx canister --network ic deposit-cycles <amount> <canister_name>
Stop the Local Network
dfx stop

Developer 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 whoami before 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.json because it defines the canisters that dfx deploy will 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 hello creates a project, and dfx deploy deploys canisters locally.
  • dfx deploy --network ic deploys to the Internet Computer mainnet and consumes real cycles.
  • Useful commands include identity management, cycles balance, canister status and top-up commands.

References and Further Reading

Original Chapter

Original Blockchain Guide article for ICP Developer Guide Chapter 2.

Read source →

ICP Canisters

Official Internet Computer documentation on canister concepts.

Read docs →

dfx deploy

Official reference for the dfx deploy command.

Read docs →

Motoko

Official Motoko documentation and language guide.

Read docs →