From 76c16e26fb5abfd0d706c764e795ad137c6c192a Mon Sep 17 00:00:00 2001
From: Anthony <10244943+antho31@users.noreply.github.com>
Date: Sun, 24 Sep 2023 19:17:52 +0200
Subject: [PATCH 01/13] feat(docs): add vite boilerplate tuto
---
docs/tutorials/overview.md | 1 +
docs/tutorials/webapp-1.md | 1903 ++++++++++++++++++++
static/img/content/tutorials/webapp-0.webp | Bin 0 -> 2013510 bytes
static/img/content/tutorials/webapp-1.webp | Bin 0 -> 10368 bytes
static/img/content/tutorials/webapp-2.webp | Bin 0 -> 45598 bytes
static/img/content/tutorials/webapp-3.webp | Bin 0 -> 10892 bytes
static/img/content/tutorials/webapp-4.webp | Bin 0 -> 21846 bytes
static/img/content/tutorials/webapp-5.webp | Bin 0 -> 23208 bytes
static/img/content/tutorials/webapp-6.webp | Bin 0 -> 135270 bytes
static/img/content/tutorials/webapp-7.webp | Bin 0 -> 25244 bytes
10 files changed, 1904 insertions(+)
create mode 100644 docs/tutorials/webapp-1.md
create mode 100644 static/img/content/tutorials/webapp-0.webp
create mode 100644 static/img/content/tutorials/webapp-1.webp
create mode 100644 static/img/content/tutorials/webapp-2.webp
create mode 100644 static/img/content/tutorials/webapp-3.webp
create mode 100644 static/img/content/tutorials/webapp-4.webp
create mode 100644 static/img/content/tutorials/webapp-5.webp
create mode 100644 static/img/content/tutorials/webapp-6.webp
create mode 100644 static/img/content/tutorials/webapp-7.webp
diff --git a/docs/tutorials/overview.md b/docs/tutorials/overview.md
index 522a9dd95f0..bcd15782bd3 100644
--- a/docs/tutorials/overview.md
+++ b/docs/tutorials/overview.md
@@ -13,6 +13,7 @@ sidebar_position: 1
* [Explorer & smart contracts](./explorer-sc)
* [Manage rules with Prolog](./prolog-1)
* [Leverage the ontology](./ontology-1)
+* [Build a Web App](./webapp-1)
## Nono's tutorials
diff --git a/docs/tutorials/webapp-1.md b/docs/tutorials/webapp-1.md
new file mode 100644
index 00000000000..06ca03013f5
--- /dev/null
+++ b/docs/tutorials/webapp-1.md
@@ -0,0 +1,1903 @@
+---
+sidebar_position: 7
+---
+
+# Build a Web App
+
+
+
+This tutorial guides you on building a web application that interacts seamlessly with the OKP4 protocol, a Cosmos-based blockchain. Whether you're a seasoned developer or just starting out, this tutorial will walk you through every step of the process using the [Vite](https://vitejs.dev/) framework and [graz](https://graz.sh/) hooks. By the end, you'll have the pieces of code you need to develop a front end ready to harness the power of the OKP4 blockchain **🚀**.
+
+:::note
+
+This is a step-by-step tutorial, but you can also directly check out [the Web UI boilerplates repository](https://github.com/okp4/web-ui-boilerplates).
+
+:::
+
+**Prerequisites:**
+
+- Basic understanding of blockchain and a [browser wallet set up with some $KNOW tokens](https://docs.okp4.network/tutorials/keplr-1)
+- Familiarity with JavaScript and modern web development, Node.js installed on your machine. This guide uses `npm`, but you’re encouraged to use `yarn` or `pnpm` as well
+
+## Importance of user interfaces interacting with the OKP4 protocol
+
+The OKP4 protocol is a blockchain built on the Cosmos SDK that enables providers to share resources like web services or datasets with anyone without the need to trust a party. A provider describes his resources ([RDF triples](https://docs.okp4.network/tutorials/ontology-1)) and the rules ([Prolog program to define access conditions, revenue sharing, and more](https://docs.okp4.network/tutorials/prolog-1)) in the blockchain.
+
+In essence, user interfaces are the key to democratizing the power of the OKP4 blockchain, making it usable and beneficial for everyone.
+
+For most users, [interacting with the protocol via terminal commands](https://docs.okp4.network/tutorials/cli-1) or delving into the intricacies of defining rules with the Prolog language remains a daunting, if not insurmountable, challenge. Similarly, the manipulation and understanding of RDF triples for semantic data can be complex without the right tools.
+
+This is where the significance of user-friendly interfaces comes into play. A well-designed user interface abstracts the complexities of the underlying protocol, offering a more intuitive and ergonomic experience. It bridges the gap between advanced blockchain technology and everyday users, ensuring that the benefits of the OKP4 protocol are accessible to a broader audience. Without these interfaces, the potential of the OKP4 protocol would remain largely untapped, confined to the realm of tech-savvy individuals.
+
+## Setting up the development environment
+
+### Vite project
+
+Let’s initiate a project with the Vite framework, which offers a lightning-fast cold server start and blazingly fast hot updates:
+
+```bash
+npm create vite@latest
+```
+
+Choose the **React** framework and the **TypeScript + SWC** variant.
+
+Once you've initialized your project with Vite, the next step is to install the necessary dependencies :
+
+```bash
+npm i
+```
+
+With the dependencies in place, it's time to fire up our development server. This will allow you to see real-time changes. Start the development server with:
+
+```bash
+npm run dev
+```
+
+Now, with the server running, you can navigate to the provided local URL in your browser and witness the live development environment. The updates will reflect instantly as you change the code, giving you a dynamic and efficient development experience.
+
+### Node.JS polyfills
+
+As we’ll deal with libraries and dependencies that were originally designed for a Node.js environment, browsers don't natively support these modules. To bridge this gap and ensure that the Vite project runs smoothly in the browser, providing "polyfills" for these Node.js modules is necessary.
+
+First, install **`node-stdlib-browser`** and the **`vite-plugin-node-stdlib-browser`** plugin:
+
+```bash
+npm i -D node-stdlib-browser vite-plugin-node-stdlib-browser
+```
+
+Then, modify the Vite config file (`vite.config.ts`):
+
+```ts
+import { defineConfig } from "vite";
+import nodePolyfills from "vite-plugin-node-stdlib-browser";
+import react from "@vitejs/plugin-react-swc";
+
+// https://vitejs.dev/config/
+export default defineConfig({
+ plugins: [nodePolyfills(), react()],
+});
+```
+
+### Cosmos SDK utilities and type definitions
+
+Now, install some packages to equip the project with a suite of tools and libraries essential for interacting with the blockchain, handling encoding/decoding, ensuring transactional integrity, and working with specific data structures defined by the OKP4 protocol.
+
+```bash
+npm i graz @cosmjs/encoding @cosmjs/proto-signing cosmjs-types @okp4/cognitarium-schema @okp4/law-stone-schema
+```
+
+- **graz**: a collection of React hooks containing everything you need to start working with the [Cosmos ecosystem](https://cosmos.network/)
+- **@cosmjs/encoding**: to transform data into a format that can be easily transported or stored.
+- **@cosmjs/proto-signing**: to ensure the data's authenticity and integrity
+- **cosmjs-types**: TypeScript type definitions related to Protocol Buffers used by Cosmos SDK
+- **@okp4/cognitarium-schema** and **@okp4/law-stone-schema**: schema definitions related to the OKP4 protocol. Schemas define the structure of transaction data, ensuring consistency and validity
+
+## Connect the web app to the OKP4 testnet
+
+Integrating a provider within the React UI is essential to establish the connection with a browser wallet like Keplr. Here is how to wrap the app with **`
+ {JSON.stringify(res, undefined, 50)}
+
+ | Address | +Creator | +Execute | +
|---|---|---|
| {row.address} | +{row.creator} | +
+ {codeId ===
+ COGNITARIUM_CODE_ID &&
+ row.creator ===
+ account?.bech32Address ? (
+ |
+
| Hashs for the {transactions.length} txs sent | +
|---|
| + + {hash} + + | +
^USO(X&D@B7=wDYu+@N<(r4j
zuk3$oflt!gyQ9(CHy?%G!FJRVDuVoU!qM00^)LuWrNzF5)#&~W3u0f|FPNE2YIMBN
zyYRP^u2<^G5;yeivE6%_;k<+s9pv)zpx&LBucHl@NS@@lPT_l*@rq^LR<0{4&EQnq
z67MIslH*dN2{XG(`$5dN7ML)6a|bRuUI!D{&oU)I%k(P5is-wztJ+O*X@a>er?MVC
zk)}&H9sGGE^&!LW`)v2KOG_M&E9@8@a2%yh-A1DySC)|@OHhj58ZvE|3Fn2}=KwP2l>AXsqrX4p=pwO^J
zYozJ-Bn}-SX6>E+;Dg|F2V8=W8NyDE`cqon>5#)7I_|RTC(+6!q`qoqjiRj5tlu>B
zW_j&rn-r48qn0?{ 0@!qyt1vT2SAB_MROviK=FcaXm+v2As7f~Vz
z&EQ=vu;WwSbboEoVb1<~j?s!K)U)d>!DkRteKkhwf}JZUzy~ kX=~cJ0
z*4p)8WHf^?x>m1sm`f<55xFx0blTAXA~KXS2;vGQQn9DhECoRX8cDEHRjMS6*k8s*
zZ+sMt6r)`uX2f;WqEJCu7z5^2ei$2&kPxzMBpCsAHP~x8A8trL@W#09XRmH7HG7qx
zw!Q7b=ZB%Dk{pX6a@|LXJyPjpqU#2~gVD5WmL^p3f@?&FT>{F!mwgQa9S-}`&tmWH
zhq8=u?RTwECa4FEOI@NAF&B->k*^Ft&bP0x{)=D7_?Leq@_fmuIHu35`5f1vuCQ>M
z*@J{y&8-G2SkJ_zbDeUPS6W(JT!Zy;ah_GG?cuDTA`J69dqm8)-?Xng$|U4)#PW6;
z&eefB8^`pXI?t}m3^N3{mdRA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