🥷 Try it live — no local setup. ICP Ninja is a web-based IDE that builds and deploys this project to the mainnet for free, right in your browser. Click the badge above, or hit Deploy if you're already in Ninja. To build and run it locally instead, follow the steps below.
This example demonstrates a simple "Hello, world!" application for ICP with both a Motoko backend canister and a frontend UI.
The backend canister stores a customizable greeting prefix (default: "Hello, ") as a stable variable, and exposes two methods:
setGreeting(prefix)— updates the greeting prefix (persisted across canister upgrades).greet(name)— returns the greeting combined with the given name (e.g., "Hello, World!").
The frontend provides a simple form where users can enter their name and receive a personalized greeting from the backend canister.
This application's logic is written in Motoko, a programming language designed specifically for developing canisters on ICP.
The /backend folder contains the Motoko canister, main.mo. The /frontend folder contains web assets for the application's user interface. The user interface is written with plain JavaScript, but any frontend framework can be used.
Edit the mops.toml file to add Motoko dependencies to the project.
Clone the example project:
git clone https://github.com/dfinity/examples
cd examples/motoko/hello_worldStart the local network and deploy:
icp network start -d
icp deployThe frontend is served by the asset canister. To run the Vite dev server with hot reload during frontend development:
npm run devWhen done, stop the local network to free the port and clear state:
icp network stopThe backend/backend.did file defines the backend canister's public interface. The frontend TypeScript bindings are auto-generated from this file during the frontend build.
If you modify the backend's public API, regenerate the .did file:
mops generate candid backendIf you base your application on this example, it is recommended that you familiarize yourself with and adhere to the security best practices for developing on ICP. This example may not implement all the best practices.