Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate Ninja projects here #1110

Merged
merged 38 commits into from
Mar 24, 2025
Merged
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0bbe473
Motoko hello world - remove ninja-specific parts
sesi200 Mar 18, 2025
9a5cffe
rust Hello World
sesi200 Mar 18, 2025
6b4c3cd
update BUILD.md
sesi200 Mar 18, 2025
b79240f
add candid-extractor to CI
sesi200 Mar 18, 2025
ef0115f
fix rust/parallel_calls
sesi200 Mar 18, 2025
cc8cd66
...again
sesi200 Mar 18, 2025
a6c0549
Update motoko/hello_world/backend/app.mo
sesi200 Mar 18, 2025
b60c947
add open-in-ninja button to readmes
sesi200 Mar 19, 2025
34f18a2
add rust/flying_ninja
sesi200 Mar 19, 2025
d16f8e9
add motoko/flying_ninja
sesi200 Mar 19, 2025
d8006e9
add motoko/llm_chatbot
sesi200 Mar 19, 2025
2ad230c
add mops to setup
sesi200 Mar 19, 2025
69e878b
add rust/llm_chatbot
sesi200 Mar 19, 2025
8e3f2c8
add motoko/daily_planner
sesi200 Mar 19, 2025
c8b8a4d
add rust/daily_planner
sesi200 Mar 19, 2025
ddd6681
candid formatting
sesi200 Mar 19, 2025
c2d0b37
add motoko/backend_only
sesi200 Mar 19, 2025
078ac16
add rust/backend_only
sesi200 Mar 19, 2025
513c076
fix backend_only
sesi200 Mar 19, 2025
9183c95
add rust/evm_block_explorer
sesi200 Mar 20, 2025
81dee2d
add motoko/evm_block_explorre
sesi200 Mar 20, 2025
850d304
forgot Makefile
sesi200 Mar 20, 2025
b637550
add motoko/filevault
sesi200 Mar 20, 2025
4b7a223
add motoko/tokenmania
sesi200 Mar 20, 2025
578b525
add rust/tokenmania
sesi200 Mar 20, 2025
77141ea
add hosting/react
sesi200 Mar 20, 2025
ee0b8bb
hosting/my_crypto_blog
sesi200 Mar 20, 2025
6fc8355
add rust/motoko who_am_i
sesi200 Mar 20, 2025
8d5054a
update codeowners
sesi200 Mar 21, 2025
70a094d
move to one .yml file for multiple examples
sesi200 Mar 21, 2025
9c51a2b
target correct branch
sesi200 Mar 21, 2025
186e585
fix matrix definition
sesi200 Mar 21, 2025
33113d5
provision linux container
sesi200 Mar 21, 2025
716de6b
skip bare ubuntu
sesi200 Mar 21, 2025
97fd3de
revert provision script changes
sesi200 Mar 21, 2025
9d95b29
skip npm i
sesi200 Mar 21, 2025
698e418
Merge branch 'master' into severin/consolidate-ninja-projects
sesi200 Mar 24, 2025
e560645
revert rust/parallel_calls to be able to merge
sesi200 Mar 24, 2025
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
1 change: 1 addition & 0 deletions .github/workflows/provision-darwin.sh
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ brew install cmake
curl --location --output install-rustup.sh "https://sh.rustup.rs"
bash install-rustup.sh -y
rustup target add wasm32-unknown-unknown
cargo install candid-extractor

# Install matchers
matchers_version=1.2.0
1 change: 1 addition & 0 deletions .github/workflows/provision-linux.sh
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ sudo apt-get install --yes cmake
wget --output-document install-rustup.sh "https://sh.rustup.rs"
sudo bash install-rustup.sh -y
rustup target add wasm32-unknown-unknown
cargo install candid-extractor

# Install matchers
matchers_version=1.2.0
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: rust-hello
name: rust-hello-world
on:
push:
branches:
- master
pull_request:
paths:
- rust/hello/**
- rust/hello_world/**
- .github/workflows/provision-darwin.sh
- .github/workflows/provision-linux.sh
- .github/workflows/rust-hello-example.yml
- .github/workflows/rust-hello-world-example.yml
- .ic-commit
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
rust-hello-darwin:
rust-hello-world-darwin:
runs-on: macos-15
steps:
- uses: actions/checkout@v1
@@ -23,10 +23,10 @@ jobs:
- name: Rust Hello Darwin
run: |
dfx start --background
pushd rust/hello
pushd rust/hello_world
make test
popd
rust-hello-linux:
rust-hello-world-linux:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v1
@@ -35,6 +35,6 @@ jobs:
- name: Rust Hello Linux
run: |
dfx start --background
pushd rust/hello
pushd rust/hello_world
make test
popd
68 changes: 31 additions & 37 deletions motoko/hello_world/BUILD.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
# Continue building locally

Projects deployed through ICP Ninja are temporary; they will only be live for 20 minutes before they are removed. The command-line tool `dfx` can be used to continue building your ICP Ninja project. `dfx` can be used to deploy projects to the mainnet for long-term production use. It is designed specifically for building ICP smart contracts and supports every feature of the network.
Projects deployed through ICP Ninja are temporary; they will only be live for 20 minutes before they are removed. The command-line tool `dfx` can be used to continue building your ICP Ninja project locally and deploy it to the mainnet.

To migrate your ICP Ninja project off of the web browser and develop it locally, follow these steps.

### 1. Install developer tools.

You can install the developer tools natively or develop using Dev Containers.
You can install the developer tools natively or use Dev Containers.

#### Option 1: Natively install developer tools

> Installing `dfx` natively is currently only supported on macOS and Linux systems. On Windows, it is recommended to use Dev Containers below.
> Installing `dfx` natively is currently only supported on macOS and Linux systems. On Windows, it is recommended to use the Dev Containers option.

1. Install `dfx` with the following command:

```

sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"
```

2. [Install NodeJS](https://nodejs.org/en/download/package-manager).
```

> On Apple Silicon (e.g., Apple M1 chip), make sure you have Rosetta installed (`softwareupdate --install-rosetta`).

2. [Install NodeJS](https://nodejs.org/en/download/package-manager).

3. For Rust projects, you will also need to:

- Install [Rust](https://doc.rust-lang.org/cargo/getting-started/installation.html#install-rust-and-cargo): `curl https://sh.rustup.rs -sSf | sh`

- Install [candid-extractor](https://crates.io/crates/candid-extractor): `cargo install candid-extractor`

4. For Motoko projects, you will also need to:
@@ -35,81 +38,72 @@ Lastly, navigate into your project's directory that you downloaded from ICP Ninj

#### Option 2: Dev Containers

Continue building your projects locally by installing the [Dev Container extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) in VS Code and [Docker](https://docs.docker.com/engine/install/).
Continue building your projects locally by installing the [Dev Container extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for VS Code and [Docker](https://docs.docker.com/engine/install/).

Make sure Docker is running, then navigate into your project's directory that you downloaded from ICP Ninja and start the Dev Container by selecting `Dev-Containers: Reopen in Container` in VS Code's command palette (F1 or Ctrl+Shift+P).
Make sure Docker is running, then navigate into your project's directory that you downloaded from ICP Ninja and start the Dev Container by selecting `Dev-Containers: Reopen in Container` in VS Code's command palette (F1 or Ctrl/Cmd+Shift+P).

> Note that local development ports (e.g. the ports used by `dfx` or `vite`) are forwarded from the Dev Container to your local machine. In the VS code terminal, use Cmd+Click on the displayed local URLs to open them in your browser. To view the current port mappings, click the "Ports" tab in the VS Code terminal window.
> Note that local development ports (e.g. the ports used by `dfx` or `vite`) are forwarded from the Dev Container to your local machine. In the VS code terminal, use Ctrl/Cmd+Click on the displayed local URLs to open them in your browser. To view the current port mappings, click the "Ports" tab in the VS Code terminal window.

### 2. Create a local developer identity.

To manage your project's canisters, it is recommended that you create a local [developer identity](https://internetcomputer.org/docs/current/developer-docs/getting-started/accounts) rather than use the `dfx` default identity that is not stored securely.
To manage your project's canisters, it is recommended that you create a local [developer identity](https://internetcomputer.org/docs/building-apps/getting-started/identities) rather than use the `dfx` default identity that is not stored securely.

To create a new identity, run the commands:

```

dfx start --background

dfx identity new IDENTITY_NAME

dfx identity use IDENTITY_NAME

```

Replace `IDENTITY_NAME` with your preferred identity name. The first command, `dfx start --background` starts the local `dfx` processes, then `dfx identity new` will create a new identity and return your identity's seed phase. Be sure to save this in a safe, secure location.
Replace `IDENTITY_NAME` with your preferred identity name. The first command `dfx start --background` starts the local `dfx` processes, then `dfx identity new` will create a new identity and return your identity's seed phase. Be sure to save this in a safe, secure location.

The third command, `dfx identity use` will tell `dfx` to use your new identity as the active identity. Any canister smart contracts created after running `dfx identity use` will be owned and controlled by the active identity.
The third command `dfx identity use` will tell `dfx` to use your new identity as the active identity. Any canister smart contracts created after running `dfx identity use` will be owned and controlled by the active identity.

Your identity will have a **principal ID** associated with it. Principal IDs are used to identify different entities on ICP, such as users and canisters.
Your identity will have a principal ID associated with it. Principal IDs are used to identify different entities on ICP, such as users and canisters.

[Learn more about ICP developer identities](https://internetcomputer.org/docs/current/developer-docs/getting-started/accounts).
[Learn more about ICP developer identities](https://internetcomputer.org/docs/building-apps/getting-started/identities).

### 3. Deploy the project locally.

Deploy your project to your local developer environment with the commands:
Deploy your project to your local developer environment with:

```
npm install
dfx deploy

```

Your project will be hosted on your local machine. The local canister URLs for your project will be shown in the terminal window as output of the `dfx deploy` command. You can open these URLs in your web browser to view the local instance of your project.

### 4. Obtain cycles.

To deploy your project to the mainnet for long term, public accessability, first you will need **[cycles](https://internetcomputer.org/docs/current/developer-docs/getting-started/cycles/overview)**. Cycles are used to pay for the resources your project uses on the mainnet, such as storage and compute.

> This cost model is known as ICP's [reverse gas model](https://internetcomputer.org/docs/current/developer-docs/gas-cost), where developers pay for their project's gas fees rather than users pay for their own gas fees. This model provides an enhanced end user experience since they do not need to hold tokens or sign transactions when using a dapp deployed on ICP.
> Learn how much a project may cost by using the [pricing calculator](https://internetcomputer.org/docs/current/developer-docs/cost-estimations-and-examples).
To deploy your project to the mainnet for long-term public accessibility, first you will need [cycles](https://internetcomputer.org/docs/building-apps/getting-started/tokens-and-cycles). Cycles are used to pay for the resources your project uses on the mainnet, such as storage and compute.

Cycles can be obtained through:
> This cost model is known as ICP's [reverse gas model](https://internetcomputer.org/docs/building-apps/essentials/gas-cost), where developers pay for their project's gas fees rather than users pay for their own gas fees. This model provides an enhanced end user experience since they do not need to hold tokens or sign transactions when using a dapp deployed on ICP.

- [Requesting a free cycles coupon](https://internetcomputer.org/docs/current/developer-docs/getting-started/cycles/cycles-faucet).
> Learn how much a project may cost by using the [pricing calculator](https://internetcomputer.org/docs/building-apps/essentials/cost-estimations-and-examples).

- [Converting ICP tokens into cycles using `dfx`](https://internetcomputer.org/docs/current/developer-docs/developer-tools/cli-tools/cli-reference/dfx-cycles#dfx-cycles-convert).
Cycles can be obtained through [converting ICP tokens into cycles using `dfx`](https://internetcomputer.org/docs/building-apps/developer-tools/dfx/dfx-cycles#dfx-cycles-convert).

### 5. Deploy to the mainnet.

Once you have cycles to deploy your project to the mainnet, run the command:
Once you have cycles, run the command:

```

dfx deploy --network ic

```

After your project has been deployed to the mainnet, it will continuously require cycles to pay for the resources it uses. You will need to [top up](https://internetcomputer.org/docs/current/developer-docs/smart-contracts/topping-up/topping-up-canister) your project's canisters or set up automatic cycles management through a service such as [CycleOps](https://cycleops.dev/).
After your project has been deployed to the mainnet, it will continuously require cycles to pay for the resources it uses. You will need to [top up](https://internetcomputer.org/docs/building-apps/canister-management/topping-up) your project's canisters or set up automatic cycles management through a service such as [CycleOps](https://cycleops.dev/).

> If your project's canisters run out of cycles, they will be removed from the network.

## Next steps

Once your project has been deployed using `dfx`, you may want to learn about:

- [Making calls to canisters](https://internetcomputer.org/docs/current/developer-docs/smart-contracts/call/overview).

- [Controlling a canister](https://internetcomputer.org/docs/current/developer-docs/smart-contracts/maintain/control).

- [Canister logging](https://internetcomputer.org/docs/current/developer-docs/smart-contracts/maintain/logs).

- [Canister settings](https://internetcomputer.org/docs/current/developer-docs/smart-contracts/maintain/settings).

- Advanced features such as [Chain Fusion](https://internetcomputer.org/docs/current/developer-docs/multi-chain/overview), [randomness](https://internetcomputer.org/docs/current/developer-docs/smart-contracts/advanced-features/randomness), [onchain signatures](https://internetcomputer.org/docs/current/developer-docs/smart-contracts/signatures/t-ecdsa), or [timers](https://internetcomputer.org/docs/current/developer-docs/smart-contracts/advanced-features/periodic-tasks).

## Additional examples

Additional code examples and sample applications can be found in the [DFINITY examples repo](https://github.com/dfinity/examples).
20 changes: 11 additions & 9 deletions motoko/hello_world/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
# Hello, world!

![Hello, world!](/examples/_attachments/hello_world.png)
![Hello, world!](hello_world.png)

This simple example demonstrates how applications on ICP are structured using a backend smart contract and a frontend smart contract, and provides an introduction to the programming language Motoko.

This variation of "Hello, world!" is written in [Motoko](https://internetcomputer.org/docs/current/motoko/main/getting-started/motoko-introduction), a programming language designed specifically for developing smart contracts (referred to as **canisters**) on ICP.
This variation of "Hello, world!" is written in [Motoko](https://internetcomputer.org/docs/motoko/main/getting-started/motoko-introduction), a programming language designed specifically for developing canisters (referred to as **canisters**) on ICP.

### Project structure
## Project structure

The `/backend` folder contains the Motoko canister, `app.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](https://mops.one/) to the project.

## Continue building locally
## Deploying from ICP Ninja

To migrate your ICP Ninja project off of the web browser and develop it locally, follow these steps.
When viewing this project in ICP Ninja, you can deploy it directly to the mainnet for free by clicking "Deploy" in the upper right corner.

### 1. Download your project from ICP Ninja using the 'Download files' button.
To **download** or **reset** the project files, click the menu option next to the deploy button.

![ICP Ninja download](/examples/_attachments/icp_ninja_download_files.png)
## Build and deploy from the command-line

### 2. Open the `BUILD.md` file for further instructions.
To migrate your ICP Ninja project off of the web browser and develop it locally, follow these steps. These steps are necessary if you want to deploy this project for long-term, production use on the mainnet.

### 1. Download your project from ICP Ninja using the 'Download files' button on the upper left corner under the pink ninja star icon.

The `BUILD.md` file included in your download will provide information about using `dfx`.
### 2. Open the `BUILD.md` file for further instructions.
43 changes: 0 additions & 43 deletions motoko/hello_world/WELCOME.md

This file was deleted.

2 changes: 1 addition & 1 deletion motoko/hello_world/backend/app.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
actor HelloWorld {
persistent actor HelloWorld {
// We store the greeting in a stable variable such that it gets persisted over canister upgrades.
stable var greeting : Text = "Hello, ";

20 changes: 20 additions & 0 deletions motoko/hello_world/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "ICP Dev Environment",
"image": "ghcr.io/dfinity/icp-dev-env-slim:17",
"forwardPorts": [4943, 5173],
"portsAttributes": {
"4943": {
"label": "dfx",
"onAutoForward": "ignore"
},
"5173": {
"label": "vite",
"onAutoForward": "openBrowser"
}
},
"customizations": {
"vscode": {
"extensions": ["dfinity-foundation.vscode-motoko"]
}
}
}
Binary file added motoko/hello_world/hello_world.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading