Skip to content

add: Deploy to ICP Ninja + standardize README #1172

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
70 changes: 9 additions & 61 deletions motoko/composite_query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,76 +27,24 @@ Each new `Bucket` must be provisioned with enough cycles to pay for its installa

`Map`'s `test` method simply `put`s 16 consecutive entries into `Map`. These entries are distributed evenly amongst the buckets making up the key-value store. Adding the first entry to a bucket takes longer than adding a subsequent one, since the bucket needs to be installed on first use.

## Prerequisites
## Deploying from ICP Ninja

- [x] Install the [IC
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
[![](https://icp.ninja/assets/open.svg)](https://icp.ninja/editor?g=https://github.com/dfinity/examples/tree/master/motoko/composite_query)

Begin by opening a terminal window.
## Build and deploy from the command-line

## Step 1: Setup the project environment
### 1. [Download and install the IC SDK.](https://internetcomputer.org/docs/building-apps/getting-started/install)

Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the commands:
### 2. Download your project from ICP Ninja using the 'Download files' button on the upper left corner, or [clone the GitHub examples repository.](https://github.com/dfinity/examples/)

### 3. Navigate into the project's directory.

```bash
cd examples/motoko/composite_query
dfx start --background
```

## Step 2: Deploy the `Map` canister

```bash
dfx deploy Map --no-wallet
```

## Step 3: Invoke the `test` method of canister `Map` to add some entries

```bash
dfx canister call Map test '()'
```
### 4. Deploy the project to your local environment:

## Step 4: Observe the following result

```bash
debug.print: putting: (0, "0")
debug.print: putting: (1, "1")
debug.print: putting: (2, "2")
debug.print: putting: (3, "3")
debug.print: putting: (4, "4")
debug.print: putting: (5, "5")
debug.print: putting: (6, "6")
debug.print: putting: (7, "7")
debug.print: putting: (8, "8")
debug.print: putting: (9, "9")
debug.print: putting: (10, "10")
debug.print: putting: (11, "11")
debug.print: putting: (12, "12")
debug.print: putting: (13, "13")
debug.print: putting: (14, "14")
debug.print: putting: (15, "15")
()
```

## Step 5: Invoke the `get` composite query method of canister `Main`

```bash
dfx canister call --query Map get '(15)'
dfx start --background --clean && dfx deploy
```

### Step 6: Observe the result

```bash
(opt "15")
```

## Resources

- [Actor classes](https://internetcomputer.org/docs/current/motoko/main/actor-classes).
- [Managing cycles](https://internetcomputer.org/docs/current/motoko/main/cycles).
- [Composite queries](https://internetcomputer.org/docs/current/motoko/main/actors-async#composite-query-functions).

## Security considerations and best practices

If you base your application on this example, we recommend you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/current/references/security/) for developing on ICP. This example may not implement all the 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.
Loading