View this sample's code on GitHub
This example demonstrates a simple "Hello, world!" application for ICP with both a Rust backend canister and a frontend UI.
The backend canister stores a customizable greeting prefix (default: "Hello, ") in stable memory, and exposes two methods:
set_greeting(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.
The /backend folder contains the Rust canister source code. 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.
Clone the example project:
git clone https://github.com/dfinity/examples
cd examples/rust/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, rebuild the canister and regenerate the .did file:
icp build backend
candid-extractor target/wasm32-unknown-unknown/release/backend.wasm > backend/backend.didIf 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.