Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# icp-cli-templates

A series of project templates to quickly get up and running
building for the [Internet Computer](https://internetcomputer.org).
Project templates to quickly get up and running building for the [Internet Computer](https://internetcomputer.org).

To use the templates install [icp-cli](https://github.com/dfinity/icp-cli), then run:
## Getting Started

```
# to interactivey select a template
Install [icp-cli](https://github.com/dfinity/icp-cli), then run:

```bash
# interactively select a template
icp new <project-name>

# to create a project from a specific template
# use a specific template
icp new <project-name> --subfolder <template-name>
```

## Templates:
## Templates

| Template | Description |
| --- | --- |
| [motoko](./motoko/) | A basic Motoko canister |
| [rust](./rust/) | A basic Rust canister |
| [hello-world](./hello-world/) | Full-stack dapp with a frontend and backend canister (Rust or Motoko) |
| [static-website](./static-website/) | A static website deployed to an asset canister |

* motoko - A basic motoko canister.
* rust - A basic rust canister.
* hello-world - Frontend and backend canister in rust or motoko.
12 changes: 6 additions & 6 deletions hello-world/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Frontend Environment Variables Example
# Hello World

This example demonstrates how to pass environment variables from the asset canister to the frontend webapp.
This example demonstrates a full-stack dapp with a frontend and backend canister, showing how to pass environment variables from the asset canister to the frontend webapp.

## Overview

Expand All @@ -11,7 +11,7 @@ This project consists of two canisters:

### Bindings Generation

The [`@icp-sdk/bindgen`](https://npmjs.com/package/@icp-sdk/bindgen) library offers a plugin for Vite that generates the TypeScript Candid bindings from the [`backend.did`](./backend/dist/hello_world.did) file. The bindings are generated at build time by Vite and are saved in the [`frontend/app/src/backend/api/`](./frontend/app/src/backend/api/) folder.
The [`@icp-sdk/bindgen`](https://npmjs.com/package/@icp-sdk/bindgen) library offers a plugin for Vite that generates the TypeScript Candid bindings from the [`backend.did`](./backend/backend.did) file. The bindings are generated at build time by Vite and are saved in the [`frontend/app/src/backend/api/`](./frontend/app/src/backend/api/) folder.

The plugin supports hot module replacement, so you can run the frontend in development mode (by running `npm run dev` in the [`frontend/app/`](./frontend/app/) folder) and make changes to the Candid declaration file to see the bindings being updated in real time.

Expand All @@ -35,12 +35,12 @@ Before you begin, ensure that you have the following installed:
- [Node.js](https://nodejs.org/)
- [npm](https://docs.npmjs.com/)

## Instructions
## Run It

First, start a local network:

```bash
icp network run --background
icp network start -d
```

Then, deploy both canisters:
Expand All @@ -51,7 +51,7 @@ icp deploy

This command will output something like this:

```bash
```
Syncing canisters:
[backend] ✔ Synced successfully: uqqxf-5h777-77774-qaaaa-cai
[frontend] ✔ Synced successfully: uxrrr-q7777-77774-qaaaq-cai # <- copy this canister id
Expand Down
2 changes: 1 addition & 1 deletion hello-world/frontend/app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import react from "@vitejs/plugin-react";
import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite";

// Change these values to match your local replica.
// The `icp network run` command will print the root key
// The `icp network start` command will print the root key
// and the `icp deploy` command will print the backend canister id.
const IC_ROOT_KEY_HEX =
"308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c050302010361008b52b4994f94c7ce4be1c1542d7c81dc79fea17d49efe8fa42e8566373581d4b969c4a59e96a0ef51b711fe5027ec01601182519d0a788f4bfe388e593b97cd1d7e44904de79422430bca686ac8c21305b3397b5ba4d7037d17877312fb7ee34";
Expand Down
8 changes: 4 additions & 4 deletions hello-world/motoko-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ The `motoko` recipe type provides a streamlined way to build Motoko canisters us

## Configuration

The [`canister.yaml`](./canister.yaml) file configures a canister using the latest `motoko` recipe:
The [`canister.yaml`](./canister.yaml) file configures a canister using the `motoko` recipe:

### Key Components

- **`type: motoko`**: Uses the Motoko recipe type
- **`entry`**: Specifies the main Motoko source file (defaults to `main.mo` if not provided)
- **`type: "@dfinity/motoko@<version>"`**: Uses the Motoko recipe type. See [available versions](https://github.com/dfinity/icp-cli-recipes/releases?q=motoko&expanded=true).
- **`main`**: Specifies the main Motoko source file (defaults to `main.mo` if not provided)

## Source Code

The [`src/main.mo`](./src/main.mo) file contains the Motoko canister implementation. This is the entry point that gets compiled by the `moc` compiler.

## How It Works

1. ICP-CLI uses the built-in `motoko` recipe resolver this depends on [mops](https://cli.mops.one/), the Motoko package manager.
1. ICP-CLI uses the built-in `motoko` recipe resolver. This depends on [mops](https://cli.mops.one/), the Motoko package manager.
2. The recipe is expanded into build steps that:
- check if mops is installed
- use the correct motoko toolchain to build the canister
Expand Down
3 changes: 1 addition & 2 deletions hello-world/motoko-backend/canister.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

name: backend
recipe:
type: "@dfinity/motoko"
type: "@dfinity/motoko@v4.1.0"
configuration:
main: src/main.mo
args: --incremental-gc
# optional
candid: backend.did

4 changes: 2 additions & 2 deletions hello-world/rust-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ The [`canister.yaml`](./canister.yaml) file configures a canister using the buil

### Key Components

- **`type: rust`**: Uses the built-in Rust recipe type
- **`type: "@dfinity/rust@<version>"`**: Uses the built-in Rust recipe type. See [available versions](https://github.com/dfinity/icp-cli-recipes/releases?q=rust&expanded=true).
- **`package`**: Specifies the Cargo package name to build (required)

## Project Structure

- [`Cargo.toml`](./Cargo.toml): Cargo project configuration with WASM target setup
- [`src/lib.rs`](./src/lib.rs): Rust canister implementation using ic-cdk
- [`.gitignore`](./gitignore): Git ignore rules for Rust projects
- [`.gitignore`](./.gitignore): Git ignore rules for Rust projects

## How It Works

Expand Down
2 changes: 1 addition & 1 deletion hello-world/rust-backend/canister.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
name: backend
recipe:
type: "@dfinity/rust@v3.0.0"
type: "@dfinity/rust@v3.1.0"
configuration:
# cargo package for canister (required field)
package: backend
Expand Down
19 changes: 9 additions & 10 deletions motoko/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,31 @@ The `motoko` recipe type provides a streamlined way to build Motoko canisters us

## Configuration

The [`icp.yaml`](./icp.yaml) file configures a canister using the latest `motoko` recipe:
The [`icp.yaml`](./icp.yaml) file configures a canister using the `motoko` recipe:

```yaml
canisters:
- name: {{project-name}}
recipe:
type: "@dfinity/motoko"
type: "@dfinity/motoko@<version>"
configuration:
main: src/main.mo
args: --incremental-gc
# optional
candid: {{project-name}}.did
```

### Key Components

- **`type: motoko`**: Uses the Motoko recipe type
- **`entry`**: Specifies the main Motoko source file (defaults to `main.mo` if not provided)
- **`type: "@dfinity/motoko@<version>"`**: Uses the Motoko recipe type. See [available versions](https://github.com/dfinity/icp-cli-recipes/releases?q=motoko&expanded=true).
- **`main`**: Specifies the main Motoko source file (defaults to `main.mo` if not provided)

## Source Code

The [`src/main.mo`](./src/main.mo) file contains the Motoko canister implementation. This is the entry point that gets compiled by the `moc` compiler.

## How It Works

1. ICP-CLI uses the built-in `motoko` recipe resolver this depends on [mops](https://cli.mops.one/), the Motoko package manager.
1. ICP-CLI uses the built-in `motoko` recipe resolver. This depends on [mops](https://cli.mops.one/), the Motoko package manager.
2. The recipe is expanded into build steps that:
- check if mops is installed
- use the correct motoko toolchain to build the canister
Expand All @@ -50,16 +49,16 @@ that the mops toolchain has been initialized: `mops toolchain init`
- Simple build workflows for Motoko projects
- Projects that don't require custom build logic

## Run it
## Run It

```
```bash
# Start a local network
icp network start --background
icp network start -d

# Build and deploy the canister
icp deploy

# make a call the canister
# Call the canister
icp canister call {{project-name}} greet '("Internet Computer")'

# Stop the network
Expand Down
3 changes: 1 addition & 2 deletions motoko/icp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
canisters:
- name: {{project-name}}
recipe:
type: "@dfinity/motoko@v3.0.0"
type: "@dfinity/motoko@v4.1.0"
configuration:
main: src/main.mo
args: --incremental-gc
# optional
candid: {{project-name}}.did

Expand Down
16 changes: 8 additions & 8 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The [`icp.yaml`](./icp.yaml) file configures a canister using the built-in `rust
canisters:
- name: backend
recipe:
type: "@dfinity/rust@v3.0.0"
type: "@dfinity/rust@<version>"
configuration:
# cargo package for canister (required field)
package: backend
Expand All @@ -28,14 +28,14 @@ canisters:

### Key Components

- **`type: rust`**: Uses the built-in Rust recipe type
- **`type: "@dfinity/rust@<version>"`**: Uses the built-in Rust recipe type. See [available versions](https://github.com/dfinity/icp-cli-recipes/releases?q=rust&expanded=true).
- **`package`**: Specifies the Cargo package name to build (required)

## Project Structure

- [`Cargo.toml`](./Cargo.toml): Cargo project configuration with WASM target setup
- [`src/lib.rs`](./src/lib.rs): Rust canister implementation using ic-cdk
- [`.gitignore`](./gitignore): Git ignore rules for Rust projects
- [`.gitignore`](./.gitignore): Git ignore rules for Rust projects

## How It Works

Expand Down Expand Up @@ -68,18 +68,18 @@ The recipe automatically:
- Canisters that don't require custom build logic
- Multi-package Rust workspaces

## Run it
## Run It

### Using the local network
### Using the Local Network

```
```bash
# Start a local network
icp network start --background
icp network start -d

# Build and deploy the canister
icp deploy

# make a call the canister
# Call the canister
icp canister call backend greet '("Internet Computer")'

# Stop the network
Expand Down
2 changes: 1 addition & 1 deletion rust/icp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
canisters:
- name: backend
recipe:
type: "@dfinity/rust@v3.0.0"
type: "@dfinity/rust@v3.1.0"
configuration:
# cargo package for canister (required field)
package: backend
Expand Down
26 changes: 13 additions & 13 deletions static-website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The [`icp.yaml`](./icp.yaml) file configures a canister using the `asset-caniste
canisters:
- name: frontend
recipe:
type: "@dfinity/asset-canister@v2.1.0"
type: "@dfinity/asset-canister@<version>"
configuration:
build:
- npm run build
Expand All @@ -23,7 +23,7 @@ canisters:

### Key Components

- **`type: asset-canister`**: Uses the asset-canister recipe for hosting static files
- **`type: "@dfinity/asset-canister@<version>"`**: Uses the asset-canister recipe for hosting static files. See [available versions](https://github.com/dfinity/icp-cli-recipes/releases?q=asset-canister&expanded=true).
- **`build`**: Specifies the build commands to run before uploading assets
- **`dir`**: Specifies the directory containing the built assets to upload

Expand All @@ -38,10 +38,10 @@ canisters:

## How It Works

1. ICP-CLI uses the `asset-canister` recipe to expand the build a sync steps of the canister.
2. The build command (`npm run build`) will use vite to compile and bundles assets in to the `dist` directory.
1. ICP-CLI uses the `asset-canister` recipe to expand the build and sync steps of the canister.
2. The build command (`npm run build`) uses Vite to compile and bundle assets into the `dist` directory.
3. The asset canister is deployed.
4. The contents of `dist` directory are synchronized to the asset canister.
4. The contents of the `dist` directory are synchronized to the asset canister.

## Prerequisites

Expand All @@ -55,23 +55,23 @@ canisters:
- Frontend applications built with Vite
- Projects that don't require a backend canister

## Run it
## Run It

```
# install dependencies:
```bash
# Install dependencies:
# Vite is required for this example to bundle assets
npm ci

# start a local network
icp network start --background
# Start a local network
icp network start -d

# build and deploy the canister
# Build and deploy the canister
icp deploy

# Open the deployed frontend in a browser using the canister ID from the output of
# `icp deploy`: `http://<frontend_canister_id>.localhost:8000/`
# `icp deploy`: http://<frontend_canister_id>.localhost:8000/

# stop the network
# Stop the network
icp network stop
```