Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Hello, world!

Open in ICP Ninja

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

Overview

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.

Project structure

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.

Build and deploy from the command line

Prerequisites

  • Install Node.js
  • Install icp-cli: npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm

Install

Clone the example project:

git clone https://github.com/dfinity/examples
cd examples/motoko/hello_world

Deployment

Start the local network and deploy:

icp network start -d
icp deploy

The frontend is served by the asset canister. To run the Vite dev server with hot reload during frontend development:

npm run dev

When done, stop the local network to free the port and clear state:

icp network stop

Updating the Candid interface

The 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 backend

Security considerations and best practices

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