From d9e81277e0ecebb628d57dcf482be7d893a7d23e Mon Sep 17 00:00:00 2001 From: Jessie Mongeon <133128541+jessiemongeon1@users.noreply.github.com> Date: Tue, 17 Jun 2025 17:14:15 -0500 Subject: [PATCH 1/2] Update README.md --- motoko/pub-sub/README.md | 54 ++++++---------------------------------- 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/motoko/pub-sub/README.md b/motoko/pub-sub/README.md index 68254f660..48e1b2a8d 100644 --- a/motoko/pub-sub/README.md +++ b/motoko/pub-sub/README.md @@ -4,58 +4,20 @@ 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: - -```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) -``` +### 4. Run `dfx start --background --clean && dfx deploy` to deploy the project to your local environment. ## 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. From 724ab14634bf1cc2703ec0431863fc31896ad85b Mon Sep 17 00:00:00 2001 From: Jessie Mongeon <133128541+jessiemongeon1@users.noreply.github.com> Date: Fri, 20 Jun 2025 08:59:05 -0500 Subject: [PATCH 2/2] Update README.md --- motoko/pub-sub/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/motoko/pub-sub/README.md b/motoko/pub-sub/README.md index 48e1b2a8d..370b95e58 100644 --- a/motoko/pub-sub/README.md +++ b/motoko/pub-sub/README.md @@ -16,7 +16,11 @@ A common problem in both distributed and decentralized systems is keeping separa ### 3. Navigate into the project's directory. -### 4. Run `dfx start --background --clean && dfx deploy` to deploy the project to your local environment. +### 4. Deploy the project to your local environment: + +``` +dfx start --background --clean && dfx deploy +``` ## Security considerations and best practices