You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c0a31b4
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: rust/qrcode/README.md
+27-46Lines changed: 27 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,74 +4,55 @@ This example shows that an Internet Computer dapp can perform a long-running com
4
4
This is possible due to a unique feature called Deterministic Time Slicing (DTS), which automatically divides long computations into smaller slices executed across multiple blocks.
5
5
Developers can write long-running code as usual and don't require anything special to take advantage of DTS, as demonstrated in this example.
6
6
7
-
You try the live version of the dapp running on the mainnet here: [https://khpe2-4qaaa-aaaao-a2fnq-cai.icp0.io/](https://khpe2-4qaaa-aaaao-a2fnq-cai.icp0.io/).
7
+
You can try the live version of the dapp running on the mainnet here: [https://khpe2-4qaaa-aaaao-a2fnq-cai.icp.net/](https://khpe2-4qaaa-aaaao-a2fnq-cai.icp.net/).
8
8
9
-
## Deploying from ICP Ninja
9
+
## How it works
10
+
11
+
The frontend consists of an HTML page with a form where users can enter text for the QR code and choose various options.
12
+
When the user clicks the "Generate!" button, a JavaScript handler initiates a call to the backend canister.
10
13
11
-
When viewing this project in ICP Ninja, you can deploy it directly to the mainnet for free by clicking "Run" in the upper right corner. Open this project in ICP Ninja:
14
+
The backend, written in Rust, uses the `qrcode-generator` and `image` crates to create a QR code from user text.
15
+
It also performs some image processing to add the Internet Computer logo and a color gradient to the final result.
16
+
Note that the amount of computational work may be significant for large images.
- Rust with the `wasm32-unknown-unknown` target: `rustup target add wasm32-unknown-unknown`
25
29
26
-
Navigate into the folder containing the project's files and start a local instance of the replica with the command:
30
+
### Install
27
31
28
-
```sh
32
+
```bash
33
+
git clone https://github.com/dfinity/examples
29
34
cd examples/rust/qrcode
30
-
dfx start --clean --background
31
35
```
32
36
33
-
You can omit the `--background` argument if you want to see log messages of the dapp.
34
-
35
-
Now you can build and deploy the dapp with a single command:
37
+
### Deploy and test
36
38
37
39
```bash
38
-
dfx deploy
40
+
icp network start -d
41
+
icp deploy
42
+
bash test.sh
43
+
icp network stop
39
44
```
40
45
41
-
If you see any error, it might be worthwhile to consult the [developer forum](https://forum.dfinity.org/).
42
-
In case of successful deployment, you will see an output with local URLs:
46
+
If you want to interact with the frontend during development, run the Vite dev server for hot reload:
43
47
44
48
```bash
45
-
Deployed canisters.
46
-
URLs:
47
-
Frontend canister via browser
48
-
qrcode_frontend: ...
49
-
Backend canister via Candid interface:
50
-
qrcode_backend: ...
49
+
npm run dev --prefix frontend
51
50
```
52
51
53
52
Navigate to the frontend URL in your browser and you'll be able to interact with the dapp.
54
53
55
54

56
55
57
-
58
-
## How it works
59
-
60
-
The initial code of the dapp was autogenerated by `dfx` using the standard frontend/backend template.
61
-
62
-
The frontend consists of an HTML page with a form where users can enter text for the QR code and choose various options.
63
-
When the user clicks the "Generate!" button, a JavaScript handler initiates a call to the backend canister.
64
-
The heavy lifting of this call is managed by `candid`, `js-agent`, and `dfx`, which automatically generates a JavaScript object from the backend's Candid interface.
65
-
That object contains `async` functions for each of the backend's endpoints, and the button handler uses them to make the calls.
66
-
67
-
The backend, written in Rust, uses the `qrcode-generator` and `image` crates to create a QR code from user text.
68
-
It also performs some image processing, to add the Internet Computer logo and a color gradient to the final result.
69
-
Note the amount of computational work may be significant for large images.
70
-
71
-
For educational purposes, the backend offers two public endpoints for QR code generation: one for updates and another for queries.
72
-
Currently, DTS is supported for updates, but not for queries.
73
-
As a result, the update endpoint has a larger instruction limit compared to the query endpoint and thus can handle larger images.
74
-
75
56
## Security considerations and best practices
76
57
77
-
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.
58
+
If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://docs.internetcomputer.org/guides/security/overview) for developing on ICP. This example may not implement all the best practices.
0 commit comments