From 84de870795743c69e777658ee572f4792483e870 Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Wed, 10 Jun 2026 23:44:07 +0200 Subject: [PATCH 1/5] chore: finalize motoko/backend_only migration to icp-cli Upgrades icp.yaml to @dfinity/motoko@v5.0.0 (no configuration block), bumps mops.toml to moc 1.9.0 / core 2.5.0 with --default-persistent-actors, removes redundant persistent keyword from actor, adds Makefile with greet test, adds CI workflow backend_only.yml, rewrites README to canonical structure, and deletes dfx.json, BUILD.md, and .devcontainer/. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/backend_only.yml | 43 +++++++++++++++++++ .../.devcontainer/devcontainer.json | 20 --------- motoko/backend_only/BUILD.md | 26 ----------- motoko/backend_only/Makefile | 8 ++++ motoko/backend_only/README.md | 37 +++------------- motoko/backend_only/backend/app.mo | 2 +- motoko/backend_only/dfx.json | 14 ------ motoko/backend_only/icp.yaml | 4 +- motoko/backend_only/mops.toml | 15 ++++--- 9 files changed, 68 insertions(+), 101 deletions(-) create mode 100644 .github/workflows/backend_only.yml delete mode 100644 motoko/backend_only/.devcontainer/devcontainer.json delete mode 100644 motoko/backend_only/BUILD.md create mode 100644 motoko/backend_only/Makefile delete mode 100644 motoko/backend_only/dfx.json diff --git a/.github/workflows/backend_only.yml b/.github/workflows/backend_only.yml new file mode 100644 index 000000000..a6179f2f6 --- /dev/null +++ b/.github/workflows/backend_only.yml @@ -0,0 +1,43 @@ +name: backend_only + +on: + push: + branches: [master] + pull_request: + paths: + - motoko/backend_only/** + - rust/backend_only/** + - .github/workflows/backend_only.yml + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + motoko-backend_only: + runs-on: ubuntu-24.04 + container: ghcr.io/dfinity/icp-dev-env-motoko:0.3.1 + env: + ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + - name: Deploy and test + working-directory: motoko/backend_only + run: | + icp network start -d + icp deploy + make test + + rust-backend_only: + runs-on: ubuntu-24.04 + container: ghcr.io/dfinity/icp-dev-env-rust:0.3.1 + env: + ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + - name: Deploy and test + working-directory: rust/backend_only + run: | + icp network start -d + icp deploy + make test diff --git a/motoko/backend_only/.devcontainer/devcontainer.json b/motoko/backend_only/.devcontainer/devcontainer.json deleted file mode 100644 index ebb0b8bcc..000000000 --- a/motoko/backend_only/.devcontainer/devcontainer.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "ICP Dev Environment", - "image": "ghcr.io/dfinity/icp-dev-env-slim:22", - "forwardPorts": [4943, 5173], - "portsAttributes": { - "4943": { - "label": "dfx", - "onAutoForward": "ignore" - }, - "5173": { - "label": "vite", - "onAutoForward": "openBrowser" - } - }, - "customizations": { - "vscode": { - "extensions": ["dfinity-foundation.vscode-motoko"] - } - } -} diff --git a/motoko/backend_only/BUILD.md b/motoko/backend_only/BUILD.md deleted file mode 100644 index 8877d3ed2..000000000 --- a/motoko/backend_only/BUILD.md +++ /dev/null @@ -1,26 +0,0 @@ -# Continue building locally - -Projects deployed through ICP Ninja are temporary; they will only be live for 30 minutes before they are removed. To continue building locally, follow these steps. - -### 1. Install developer tools - -Install [Node.js](https://nodejs.org/en/download/) and [icp-cli](https://cli.internetcomputer.org): - -```bash -npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm -``` - -Then navigate into your project's directory that you downloaded from ICP Ninja. - -### 2. Deploy locally - -Start the local network and deploy the project: - -```bash -icp network start -d -icp deploy -``` - -## Additional examples - -Additional code examples and sample applications can be found in the [DFINITY examples repo](https://github.com/dfinity/examples). diff --git a/motoko/backend_only/Makefile b/motoko/backend_only/Makefile new file mode 100644 index 000000000..08b2e2255 --- /dev/null +++ b/motoko/backend_only/Makefile @@ -0,0 +1,8 @@ +.PHONY: test + +test: + @echo "=== Test 1: greet returns greeting ===" + @result=$$(icp canister call backend greet '("World")') && \ + echo "$$result" && \ + echo "$$result" | grep -q '"Hello, World!"' && \ + echo "PASS" || (echo "FAIL" && exit 1) diff --git a/motoko/backend_only/README.md b/motoko/backend_only/README.md index 1b694300a..b904b1ed8 100644 --- a/motoko/backend_only/README.md +++ b/motoko/backend_only/README.md @@ -1,55 +1,30 @@ # Motoko backend -[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/motoko/backend_only) - -## Overview - -This backend only project demonstrates how to write a simple smart contract for ICP. - -## Deploying from ICP Ninja - -This example can be deployed directly from [ICP Ninja](https://icp.ninja), a browser-based IDE for ICP. To continue developing locally after deploying from ICP Ninja, see [BUILD.md](BUILD.md). - -[![Open in ICP Ninja](https://icp.ninja/assets/open.svg)](https://icp.ninja/i?g=https://github.com/dfinity/examples/motoko/backend_only) - -> **Note:** ICP Ninja currently uses `dfx` under the hood, which is why this example includes a `dfx.json` configuration file. `dfx` is the legacy CLI, being superseded by [icp-cli](https://cli.internetcomputer.org), which is what developers should use for local development. +This backend-only example demonstrates how to write a simple smart contract for ICP. It implements a single `greet(name)` query function that returns a greeting string. ## Build and deploy from the command line ### Prerequisites -- [x] Install [Node.js](https://nodejs.org/en/download/) -- [x] Install [icp-cli](https://cli.internetcomputer.org): `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm` +- Node.js +- icp-cli: `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm` ### Install -Clone the example project: - ```bash git clone https://github.com/dfinity/examples cd examples/motoko/backend_only ``` -### Deployment - -Start the local network: +### Deploy and test ```bash icp network start -d -``` - -Deploy the canister: - -```bash icp deploy -``` - -Stop the local network when done: - -```bash +make test icp network stop ``` ## 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](https://internetcomputer.org/docs/building-apps/security/overview) for developing on ICP. This example may not implement all the best practices. +Refer to the [security best practices](https://docs.internetcomputer.org/guides/security/overview) for information on security and best practices for your ICP app. diff --git a/motoko/backend_only/backend/app.mo b/motoko/backend_only/backend/app.mo index 673eba2c1..89f994633 100644 --- a/motoko/backend_only/backend/app.mo +++ b/motoko/backend_only/backend/app.mo @@ -1,4 +1,4 @@ -persistent actor HelloWorld { +actor HelloWorld { public query func greet(name : Text) : async Text { return "Hello, " # name # "!"; }; diff --git a/motoko/backend_only/dfx.json b/motoko/backend_only/dfx.json deleted file mode 100644 index 5d7f13c3e..000000000 --- a/motoko/backend_only/dfx.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "canisters": { - "backend": { - "main": "backend/app.mo", - "type": "motoko", - "args": "--enhanced-orthogonal-persistence" - } - }, - "defaults": { - "build": { - "packtool": "mops sources" - } - } -} diff --git a/motoko/backend_only/icp.yaml b/motoko/backend_only/icp.yaml index b83566d40..fb741fade 100644 --- a/motoko/backend_only/icp.yaml +++ b/motoko/backend_only/icp.yaml @@ -1,6 +1,4 @@ canisters: - name: backend recipe: - type: "@dfinity/motoko@v4.1.0" - configuration: - main: backend/app.mo + type: "@dfinity/motoko@v5.0.0" diff --git a/motoko/backend_only/mops.toml b/motoko/backend_only/mops.toml index dc89d0891..d3f244542 100644 --- a/motoko/backend_only/mops.toml +++ b/motoko/backend_only/mops.toml @@ -1,11 +1,14 @@ [toolchain] -moc = "1.5.1" +moc = "1.9.0" [dependencies] -core = "2.4.0" +core = "2.5.0" [moc] -# M0236: use context dot notation (e.g. x.toText() instead of Nat.toText(x)) -# M0237: redundant explicit implicit arguments (e.g. Nat.compare is inferred automatically) -# M0223: redundant type instantiation (e.g. Array.tabulate instead of Array.tabulate) -args = ["-W=M0236,M0237,M0223"] +# M0236: use context dot notation +# M0237: redundant explicit implicit arguments +# M0223: redundant type instantiation +args = ["--default-persistent-actors", "-W=M0236,M0237,M0223"] + +[canisters.backend] +main = "backend/app.mo" From 866b9d23341b5f71fb2ede3a0d5a8b872a23e250 Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Wed, 10 Jun 2026 23:56:22 +0200 Subject: [PATCH 2/5] fix: migrate rust/backend_only to @dfinity/rust@v3.2.0 with candid; add Makefile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Bump recipe to @dfinity/rust@v3.2.0 with candid: backend/backend.did (v3.1.0 required candid-extractor which is not in the container) - Bump ic-cdk 0.16 → 0.20, candid 0.10.10 → 0.10 - Commit backend/backend.did (greet interface) - Add Makefile with test - Delete dfx.json, BUILD.md, .devcontainer/ Co-Authored-By: Claude Sonnet 4.6 --- .../.devcontainer/devcontainer.json | 20 -------------- rust/backend_only/BUILD.md | 26 ------------------- rust/backend_only/Makefile | 8 ++++++ rust/backend_only/backend/Cargo.toml | 4 +-- rust/backend_only/backend/backend.did | 3 +++ rust/backend_only/dfx.json | 20 -------------- rust/backend_only/icp.yaml | 3 ++- 7 files changed, 15 insertions(+), 69 deletions(-) delete mode 100644 rust/backend_only/.devcontainer/devcontainer.json delete mode 100644 rust/backend_only/BUILD.md create mode 100644 rust/backend_only/Makefile create mode 100644 rust/backend_only/backend/backend.did delete mode 100644 rust/backend_only/dfx.json diff --git a/rust/backend_only/.devcontainer/devcontainer.json b/rust/backend_only/.devcontainer/devcontainer.json deleted file mode 100644 index ebb0b8bcc..000000000 --- a/rust/backend_only/.devcontainer/devcontainer.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "ICP Dev Environment", - "image": "ghcr.io/dfinity/icp-dev-env-slim:22", - "forwardPorts": [4943, 5173], - "portsAttributes": { - "4943": { - "label": "dfx", - "onAutoForward": "ignore" - }, - "5173": { - "label": "vite", - "onAutoForward": "openBrowser" - } - }, - "customizations": { - "vscode": { - "extensions": ["dfinity-foundation.vscode-motoko"] - } - } -} diff --git a/rust/backend_only/BUILD.md b/rust/backend_only/BUILD.md deleted file mode 100644 index ffb6557ec..000000000 --- a/rust/backend_only/BUILD.md +++ /dev/null @@ -1,26 +0,0 @@ -# Continue building locally - -Projects deployed through ICP Ninja are temporary; they will only be live for 30 minutes before they are removed. To continue building locally, follow these steps. - -### 1. Install developer tools - -Install [Node.js](https://nodejs.org/en/download/) and [icp-cli](https://cli.icp.build): - -```bash -npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm -``` - -Then navigate into your project's directory that you downloaded from ICP Ninja. - -### 2. Deploy locally - -Start the local network and deploy the project: - -```bash -icp network start -d -icp deploy -``` - -## Additional examples - -Additional code examples and sample applications can be found in the [DFINITY examples repo](https://github.com/dfinity/examples). diff --git a/rust/backend_only/Makefile b/rust/backend_only/Makefile new file mode 100644 index 000000000..390eb4bbf --- /dev/null +++ b/rust/backend_only/Makefile @@ -0,0 +1,8 @@ +.PHONY: test + +test: + @echo "=== Test 1/1: greet() returns a greeting ===" + @result=$$(icp canister call backend greet '("World")') && \ + echo "$$result" && \ + echo "$$result" | grep -q 'Hello, World!' && \ + echo "PASS" || (echo "FAIL" && exit 1) diff --git a/rust/backend_only/backend/Cargo.toml b/rust/backend_only/backend/Cargo.toml index 268b84c42..22acbdec9 100644 --- a/rust/backend_only/backend/Cargo.toml +++ b/rust/backend_only/backend/Cargo.toml @@ -10,5 +10,5 @@ crate-type = ["cdylib"] path = "lib.rs" [dependencies] -candid = "0.10.10" -ic-cdk = "0.16.0" +candid = "0.10" +ic-cdk = "0.20" diff --git a/rust/backend_only/backend/backend.did b/rust/backend_only/backend/backend.did new file mode 100644 index 000000000..a3129c1f0 --- /dev/null +++ b/rust/backend_only/backend/backend.did @@ -0,0 +1,3 @@ +service : { + greet: (text) -> (text) query; +} diff --git a/rust/backend_only/dfx.json b/rust/backend_only/dfx.json deleted file mode 100644 index eaa52140b..000000000 --- a/rust/backend_only/dfx.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "canisters": { - "backend": { - "candid": "backend/backend.did", - "type": "custom", - "shrink": true, - "gzip": true, - "wasm": "target/wasm32-unknown-unknown/release/backend.wasm", - "build": [ - "cargo build --target wasm32-unknown-unknown --release -p backend", - "candid-extractor target/wasm32-unknown-unknown/release/backend.wasm > backend/backend.did" - ], - "metadata": [ - { - "name": "candid:service" - } - ] - } - } -} diff --git a/rust/backend_only/icp.yaml b/rust/backend_only/icp.yaml index b331b4584..bfcaeb562 100644 --- a/rust/backend_only/icp.yaml +++ b/rust/backend_only/icp.yaml @@ -1,6 +1,7 @@ canisters: - name: backend recipe: - type: "@dfinity/rust@v3.1.0" + type: "@dfinity/rust@v3.2.0" configuration: package: backend + candid: backend/backend.did From 50b468ea06fcf37423c35505671f2830a5e99b86 Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Thu, 11 Jun 2026 00:41:11 +0200 Subject: [PATCH 3/5] chore: bump to icp-dev-env 0.3.2; let recipe extract Candid from WASM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - icp-dev-env 0.3.2 includes candid-extractor — no longer need to commit backend.did as a workaround - Remove candid: backend/backend.did from icp.yaml (backend-only, no bindings) - Delete rust/backend_only/backend/backend.did - Bump both motoko and rust container images to 0.3.2 Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/backend_only.yml | 4 ++-- rust/backend_only/backend/backend.did | 3 --- rust/backend_only/icp.yaml | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 rust/backend_only/backend/backend.did diff --git a/.github/workflows/backend_only.yml b/.github/workflows/backend_only.yml index a6179f2f6..370d80c7c 100644 --- a/.github/workflows/backend_only.yml +++ b/.github/workflows/backend_only.yml @@ -16,7 +16,7 @@ concurrency: jobs: motoko-backend_only: runs-on: ubuntu-24.04 - container: ghcr.io/dfinity/icp-dev-env-motoko:0.3.1 + container: ghcr.io/dfinity/icp-dev-env-motoko:0.3.2 env: ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: @@ -30,7 +30,7 @@ jobs: rust-backend_only: runs-on: ubuntu-24.04 - container: ghcr.io/dfinity/icp-dev-env-rust:0.3.1 + container: ghcr.io/dfinity/icp-dev-env-rust:0.3.2 env: ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: diff --git a/rust/backend_only/backend/backend.did b/rust/backend_only/backend/backend.did deleted file mode 100644 index a3129c1f0..000000000 --- a/rust/backend_only/backend/backend.did +++ /dev/null @@ -1,3 +0,0 @@ -service : { - greet: (text) -> (text) query; -} diff --git a/rust/backend_only/icp.yaml b/rust/backend_only/icp.yaml index bfcaeb562..ff944789f 100644 --- a/rust/backend_only/icp.yaml +++ b/rust/backend_only/icp.yaml @@ -4,4 +4,3 @@ canisters: type: "@dfinity/rust@v3.2.0" configuration: package: backend - candid: backend/backend.did From 7decefb90ff3e6669cbc334c1369c15cad5203bb Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Thu, 11 Jun 2026 00:50:56 +0200 Subject: [PATCH 4/5] revert: back to icp-dev-env 0.3.1 (0.3.2 not yet on ghcr.io) Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/backend_only.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend_only.yml b/.github/workflows/backend_only.yml index 370d80c7c..a6179f2f6 100644 --- a/.github/workflows/backend_only.yml +++ b/.github/workflows/backend_only.yml @@ -16,7 +16,7 @@ concurrency: jobs: motoko-backend_only: runs-on: ubuntu-24.04 - container: ghcr.io/dfinity/icp-dev-env-motoko:0.3.2 + container: ghcr.io/dfinity/icp-dev-env-motoko:0.3.1 env: ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: @@ -30,7 +30,7 @@ jobs: rust-backend_only: runs-on: ubuntu-24.04 - container: ghcr.io/dfinity/icp-dev-env-rust:0.3.2 + container: ghcr.io/dfinity/icp-dev-env-rust:0.3.1 env: ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: From 90cad67a26593dd3706b228535135659face5652 Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Thu, 11 Jun 2026 01:21:25 +0200 Subject: [PATCH 5/5] chore: bump icp-dev-env to 0.3.2 (images now published) Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/backend_only.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend_only.yml b/.github/workflows/backend_only.yml index a6179f2f6..370d80c7c 100644 --- a/.github/workflows/backend_only.yml +++ b/.github/workflows/backend_only.yml @@ -16,7 +16,7 @@ concurrency: jobs: motoko-backend_only: runs-on: ubuntu-24.04 - container: ghcr.io/dfinity/icp-dev-env-motoko:0.3.1 + container: ghcr.io/dfinity/icp-dev-env-motoko:0.3.2 env: ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: @@ -30,7 +30,7 @@ jobs: rust-backend_only: runs-on: ubuntu-24.04 - container: ghcr.io/dfinity/icp-dev-env-rust:0.3.1 + container: ghcr.io/dfinity/icp-dev-env-rust:0.3.2 env: ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: