Skip to content
Draft
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
43 changes: 43 additions & 0 deletions .github/workflows/backend_only.yml
Original file line number Diff line number Diff line change
@@ -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.2
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.2
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
20 changes: 0 additions & 20 deletions motoko/backend_only/.devcontainer/devcontainer.json

This file was deleted.

26 changes: 0 additions & 26 deletions motoko/backend_only/BUILD.md

This file was deleted.

8 changes: 8 additions & 0 deletions motoko/backend_only/Makefile
Original file line number Diff line number Diff line change
@@ -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)
37 changes: 6 additions & 31 deletions motoko/backend_only/README.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion motoko/backend_only/backend/app.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
persistent actor HelloWorld {
actor HelloWorld {
public query func greet(name : Text) : async Text {
return "Hello, " # name # "!";
};
Expand Down
14 changes: 0 additions & 14 deletions motoko/backend_only/dfx.json

This file was deleted.

4 changes: 1 addition & 3 deletions motoko/backend_only/icp.yaml
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 9 additions & 6 deletions motoko/backend_only/mops.toml
Original file line number Diff line number Diff line change
@@ -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<T>)
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"
20 changes: 0 additions & 20 deletions rust/backend_only/.devcontainer/devcontainer.json

This file was deleted.

26 changes: 0 additions & 26 deletions rust/backend_only/BUILD.md

This file was deleted.

8 changes: 8 additions & 0 deletions rust/backend_only/Makefile
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions rust/backend_only/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 0 additions & 20 deletions rust/backend_only/dfx.json

This file was deleted.

2 changes: 1 addition & 1 deletion rust/backend_only/icp.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
canisters:
- name: backend
recipe:
type: "@dfinity/rust@v3.1.0"
type: "@dfinity/rust@v3.2.0"
configuration:
package: backend
Loading