Skip to content

add: Deploy to ICP Ninja + Standardize README #1183

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 2 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
52 changes: 9 additions & 43 deletions motoko/pub-sub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,24 @@ This sample project demonstrates how functions may be passed as arguments of int

A common problem in both distributed and decentralized systems is keeping separate services (or canisters) synchronized with one another. While there are many potential solutions to this problem, a popular one is the publisher/subscriber pattern or "PubSub". PubSub is an especially valuable pattern on the Internet Computer as its primary drawback, message delivery failures, does not apply.

## Prerequisites
This example requires an installation of:
## Deploying from ICP Ninja

- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/index.mdx).
- [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/pub-sub)

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/)

```bash
cd examples/motoko/pub-sub
dfx start --background
```
### 3. Navigate into the project's directory.

## Step 2: Deploy the canisters:
### 4. Deploy the project to your local environment:

```bash
dfx deploy
```

## Step 3: Subscribe to the "Apples" topic

```bash
dfx canister call sub init '("Apples")'
```

## Step 4: Publish to the "Apples" topic

```bash
dfx canister call pub publish '(record { "topic" = "Apples"; "value" = 2 })'
```

## Step 5: Receive your subscription

```bash
dfx canister call sub getCount
```

The output should resemble the following:

```bash
(2 : nat)
dfx start --background --clean && dfx deploy
```

## 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 the Internet Computer. This example may not implement all the best practices.

For example, the following aspects are particularly relevant for this app, since it makes inter-canister calls:
* [Be aware that state may change during inter-canister calls.](https://internetcomputer.org/docs/current/developer-docs/security/security-best-practices/overview)
* [Only make inter-canister calls to trustworthy canisters.](https://internetcomputer.org/docs/current/developer-docs/security/security-best-practices/overview)
* [Don’t panic after await and don’t lock shared resources across await boundaries.](https://internetcomputer.org/docs/current/developer-docs/security/security-best-practices/overview)
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