<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: xutweety</title>
    <description>The latest articles on Forem by xutweety (@xutweety).</description>
    <link>https://forem.com/xutweety</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F993329%2F1f04a307-1b91-418d-bbf2-935f6636df8e.png</url>
      <title>Forem: xutweety</title>
      <link>https://forem.com/xutweety</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/xutweety"/>
    <language>en</language>
    <item>
      <title>Build a decentralized CRUD application using Typescript, React, and DB3.js</title>
      <dc:creator>xutweety</dc:creator>
      <pubDate>Fri, 03 Mar 2023 10:02:32 +0000</pubDate>
      <link>https://forem.com/db3network/build-a-decentralized-crud-application-using-typescript-react-and-db3js-a49</link>
      <guid>https://forem.com/db3network/build-a-decentralized-crud-application-using-typescript-react-and-db3js-a49</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt; is a JavaScript API development toolkit that complements Web3.js in dApp development. With it, you can write data into the &lt;a href="https://github.com/dbpunk-labs/db3"&gt;&lt;strong&gt;DB3 Network&lt;/strong&gt;&lt;/a&gt; (a decentralized database), query data, and more.&lt;/p&gt;

&lt;p&gt;To help more front-end developers seamlessly switch from the web2 world to the web3 era and quickly build decentralized applications, &lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt; adopt the philosophy of the Firebase SDK in mind because &lt;a href="https://github.com/dbpunk-labs/db3"&gt;&lt;strong&gt;DB3 Network&lt;/strong&gt;&lt;/a&gt; aims to become a decentralized alternative to Firebase Firestore.&lt;/p&gt;

&lt;p&gt;Firebase is one of the most popular backend-as-a-service options in modern technology stacks, suitable for multiple platforms, including mobile, Unity, Java, C++, and web. The drawback of the past SDK V8 version was its large size, which caused slow network connections. V9 version made improvements such as functional programming style, no-side-effect imports, etc. These more advanced design concepts reduced the size of the V9 version by 80%. How to design &lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt; to be more lightweight and help decentralized applications improve their user experience on mobile devices, etc., is also one of the directions in which &lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt; needs to learn from Firebase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using &lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt; to Show the CRUD Process of Decentralized Applications
&lt;/h2&gt;

&lt;p&gt;This article will transform a classic demo example of &lt;a href="https://github.com/tastejs/todomvc"&gt;TodoMVC&lt;/a&gt; into a decentralized TodoMVC using &lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt;. We will show how to use &lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt; to perform CRUD operations and demonstrate the process of &lt;em&gt;writing, reading, modifying, and deleting&lt;/em&gt; data in decentralized applications. We will complete a to-do list application as shown below. You can click &lt;a href="https://github.com/dbpunk-labs/db3.js/tree/main/examples/todomvc"&gt;here&lt;/a&gt; to view the demo code.&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@imotai/DB3-Network-CRUD-TodoMVC-Demo?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;p&gt;During the process, we will display the following CRUD operations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create&lt;/strong&gt;: Enter a new to-do item, add the to-do item to the list, and complete the addition process by pressing Enter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Read&lt;/strong&gt;: Listen to the document in the collection and display the list, including all to-dos, active to-dos, and completed to-dos.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: Modify the content of the to-do item; when it is done, click it to mark it as completed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Delete&lt;/strong&gt;: Delete the to-do items.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lm0ZUjOR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zz6p0idufmuzp8frlvu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lm0ZUjOR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9zz6p0idufmuzp8frlvu.png" alt="CRUD in the demo" width="880" height="623"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Please note that there may be some instability as we connect to a test node in our network. If you encounter any problems, you can try again later or submit a bug on &lt;a href="https://%5Bgithub.com/dbpunk-labs/db3.js/issues/"&gt;GitHub&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Running the Demo Directly
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Start &lt;a href="https://github.com/dbpunk-labs/db3"&gt;DB3 Network&lt;/a&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/dbpunk-labs/db3.git
&lt;span class="nb"&gt;cd &lt;/span&gt;db3 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; bash install_env.sh &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; cargo build
&lt;span class="c"&gt;# start localnet&lt;/span&gt;
&lt;span class="nb"&gt;cd &lt;/span&gt;tools &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;  sh start_localnet.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After starting, you can see network activity similar to the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NQFuN8Qh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gj9nwekhvbc44kg5zlyv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NQFuN8Qh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gj9nwekhvbc44kg5zlyv.png" alt="network log" width="880" height="368"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: Start DB3 CLI, Create Database, and Collection
&lt;/h3&gt;

&lt;p&gt;The database address &lt;code&gt;0x7720f39c6bf077582ab89797c90ca7701ea82ea9&lt;/code&gt; in the codeblock below is the database address for the todo application to be created next. Then, we create new collection under its database address, named. &lt;code&gt;todos&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;base&lt;span class="o"&gt;)&lt;/span&gt;  ✘ xuman@192  ~/Documents/GitHub/dbpunkslabs/db3   main  ./target/debug/db3 console       

██████╗ ██████╗ ██████╗ 
██╔══██╗██╔══██╗╚════██╗
██║  ██║██████╔╝ █████╔╝
██║  ██║██╔══██╗ ╚═══██╗
██████╔╝██████╔╝██████╔╝
╚═════╝ ╚═════╝ ╚═════╝ 
@db3.network🚀🚀🚀
db3&amp;gt;-&lt;span class="nv"&gt;$ &lt;/span&gt;new-db
 database address                           | transaction &lt;span class="nb"&gt;id&lt;/span&gt; 
&lt;span class="nt"&gt;--------------------------------------------&lt;/span&gt;+----------------------------------------------
 0x7720f39c6bf077582ab89797c90ca7701ea82ea9 | dw44D6TeBRRZJ8U6fCiVvLPuAvi/B/xBSOAtYMJgUBk&lt;span class="o"&gt;=&lt;/span&gt;
db3&amp;gt;-&lt;span class="nv"&gt;$ &lt;/span&gt;new-collection &lt;span class="nt"&gt;--addr&lt;/span&gt; 0x7720f39c6bf077582ab89797c90ca7701ea82ea9 &lt;span class="nt"&gt;--name&lt;/span&gt; todos &lt;span class="nt"&gt;--index&lt;/span&gt; &lt;span class="s1"&gt;'{"id":0, "name":"owner_idx","fields":[{"field_path":"owner","value_mode":{"Order":1}}]}'&lt;/span&gt;
send add collection &lt;span class="k"&gt;done &lt;/span&gt;with tx
&lt;span class="nv"&gt;o6m7DHogWxaFb6jLQRu5aPzPSwgAP5JK1kBYohNiq7c&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Step 3: Running the Todo Application
&lt;/h3&gt;

&lt;p&gt;Download the todo application code and open the corresponding demo folder.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &amp;lt;https://github.com/dbpunk-labs/db3.js.git&amp;gt;
&lt;span class="nb"&gt;cd &lt;/span&gt;db3.js/examples/todomvc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next, build:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn
yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then use a browser to open &lt;a href="http://localhost:3000/"&gt;http://localhost:3000/&lt;/a&gt; to see the todo application.&lt;/p&gt;
&lt;h2&gt;
  
  
  Code Overview
&lt;/h2&gt;

&lt;p&gt;Next, we will explain the project's creation process and provide code examples of key parts.&lt;/p&gt;
&lt;h3&gt;
  
  
  File Overview:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;├── src
│   ├── App.tsx
│   ├── base.css
│   ├── context.ts
│   ├── footer.tsx
│   ├── header.tsx
│   ├── index.tsx
│   ├── link.tsx
│   ├── logo.svg
│   ├── main_section.tsx
│   ├── reducer.ts
│   ├── todo_input.tsx
│   ├── todo_item.tsx
│   └── todo_list.tsx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Briefly explain the functions of the above files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;header&lt;/strong&gt;: displays the application's top "what needs to be done", including the form &lt;code&gt;addTodo&lt;/code&gt; for creating a new to-do item by calling operations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;footer&lt;/strong&gt;: displays aggregation information and controls, as well as a menu classification bar "all/active/completed."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;main_section&lt;/strong&gt;: displays the middle part of the to-do list.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;reducer&lt;/strong&gt; and &lt;strong&gt;todo_item&lt;/strong&gt;: define the operations of CRUD and the update of operation status, which is the focus of this article.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;todo_input&lt;/strong&gt;: mainly defines the content input and the event monitoring of Enter.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Component Overview
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5HdvvpCo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1677775182222/b97f65fc-8432-40fe-896b-220b1eda997d.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5HdvvpCo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1677775182222/b97f65fc-8432-40fe-896b-220b1eda997d.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="relationship of the imports" width="880" height="511"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The referencing relationship is quite complex, but don't worry; we can see that almost all other components are imported from the reducer, mainly because the reducer file defines almost all states, operations, and state change processes. The CRUD process that we focus on this time is also mainly described by the &lt;strong&gt;Reducer.ts&lt;/strong&gt; file.&lt;/p&gt;
&lt;h3&gt;
  
  
  State, Operations, and Filtering Processes in Reducer
&lt;/h3&gt;
&lt;h4&gt;
  
  
  State and Content:
&lt;/h4&gt;

&lt;p&gt;In concept, this Todo application mainly needs to define the following two parts of content:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A list of to-do items&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The current filtering option (all/todo/complete)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each to-do item needs to store the following information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The text content of the to-do item (line 17)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A boolean value indicating whether it has been completed (line 18)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The owner of this to-do item data (line 19) (The owner concept is unique to the DB3 Network, and you can view the &lt;a href="https://github.com/dbpunk-labs/db3/issues/271"&gt;issue&lt;/a&gt;.)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The filtering process needs to be determined based on the status information of the to-do items:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;An array of document lists (line 23)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A boolean value indicating whether it is loaded (line 24)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The name of the collection is stored in DB3 (line 26)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The user's wallet address (line 27) (PS. The wallet and its corresponding signature are automatically generated. For quick demo purposes, these pieces of information are currently stored directly in the browser. In the future, &lt;a href="https://github.com/dbpunk-labs/db3.js/issues/40"&gt;we will support the MetaMask wallet&lt;/a&gt;.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Where to render and display under which filtering menu (line 28)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  CRUD Operations
&lt;/h4&gt;

&lt;p&gt;In the CRUD process, the first step is to enumerate the CRUD &lt;code&gt;action&lt;/code&gt; (line 31-36): &lt;code&gt;INSERT&lt;/code&gt; / &lt;code&gt;UPDATE&lt;/code&gt; / &lt;code&gt;QUERY&lt;/code&gt; / &lt;code&gt;DELETE&lt;/code&gt;; the second step is that since we are not updating synchronously here, that is, the &lt;code&gt;TodoState&lt;/code&gt; will not be updated immediately when dispatching the &lt;code&gt;action&lt;/code&gt;. Therefore, we need to define which information changes asynchronously during this process (line 38-47).&lt;/p&gt;

&lt;p&gt;Then, we can trigger asynchronous operations according to the CRUD &lt;code&gt;action&lt;/code&gt; (line 53-99):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;INSERT&lt;/code&gt; will trigger the &lt;code&gt;collection&lt;/code&gt; and &lt;code&gt;addDoc&lt;/code&gt; methods of &lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt;, complete adding the &lt;code&gt;addDoc&lt;/code&gt; to the corresponding &lt;code&gt;db&lt;/code&gt; and &lt;code&gt;collection&lt;/code&gt;, and then trigger the &lt;code&gt;QUERY&lt;/code&gt; operation accordingly;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;UPDATE&lt;/code&gt; will trigger the &lt;code&gt;updateDoc&lt;/code&gt; method of &lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt;, and the data in &lt;code&gt;DB3Store&lt;/code&gt; will be updated accordingly, and the size and field of the doc will also be updated accordingly. After completion, the &lt;code&gt;QUERY&lt;/code&gt; operation will also be triggered;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DELETE&lt;/code&gt; will trigger the &lt;code&gt;deleteDoc&lt;/code&gt; method of &lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt;, and the data in &lt;code&gt;DB3Store&lt;/code&gt; will be updated accordingly. After completion, the &lt;code&gt;QUERY&lt;/code&gt; operation will also be triggered;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;QUERY&lt;/code&gt; will trigger the &lt;code&gt;getDocs&lt;/code&gt; method of &lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt; to list all docs, and at the same time, it will verify whether the &lt;code&gt;owner&lt;/code&gt; of each to-do item is the current &lt;code&gt;userAddress&lt;/code&gt; to filter the to-do items that belong to the current &lt;code&gt;userAddress&lt;/code&gt;. After filtering, it will be refreshed;&lt;/p&gt;

&lt;p&gt;All the above-mentioned &lt;a href="https://github.com/dbpunk-labs/db3.js/"&gt;DB3.js&lt;/a&gt; methods (except for &lt;code&gt;getDocs&lt;/code&gt;) are collectively called &lt;a href="https://github.com/dbpunk-labs/db3/blob/main/docs/images/db3-mutaion.svg"&gt;&lt;em&gt;mutations&lt;/em&gt;&lt;/a&gt; in DB3 Network. They will communicate with DB3 Network; all operation results will be recorded on the chain and cannot be tampered with.&lt;/p&gt;
&lt;h4&gt;
  
  
  Filtering and State Updates
&lt;/h4&gt;

&lt;p&gt;As mentioned earlier, defining the filtering process is another key notion this application must fulfill. The &lt;code&gt;runfilter&lt;/code&gt; method (lines 103-116) is defined to filter the display based on the status of each to-do item.&lt;/p&gt;

&lt;p&gt;The main function of the reducer is to describe the process of generating &lt;code&gt;nextState&lt;/code&gt; based on &lt;code&gt;(previousState, action)&lt;/code&gt;. Therefore, after the asynchronous operation is completed, when &lt;code&gt;REFRESH&lt;/code&gt; is triggered, &lt;code&gt;nextState&lt;/code&gt; remains unchanged, but the new &lt;code&gt;todoList: resultSet&lt;/code&gt; is displayed; when &lt;code&gt;LOADING&lt;/code&gt; and &lt;code&gt;UNLOADING&lt;/code&gt; are triggered, nextState remains unchanged.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;The above is from the &lt;a href="https://github.com/dbpunk-labs/db3.js/tree/main/examples/todomvc"&gt;sample code&lt;/a&gt; of &lt;code&gt;the&lt;/code&gt; TodoMVC. As mentioned earlier, we will add two features in the future:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Adding support for MetaMask wallet addresses&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add network operation logs in UI&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you find our content helpful, please give us a &lt;a href="https://github.com/dbpunk-labs/db3/"&gt;Github&lt;/a&gt; ⭐️.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/chroline/why-the-new-firebase-web-v9-modular-sdk-is-a-game-changer-nph"&gt;https://dev.to/chroline/why-the-new-firebase-web-v9-modular-sdk-is-a-game-changer-nph&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://zhuanlan.zhihu.com/p/551650121"&gt;https://zhuanlan.zhihu.com/p/551650121&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://redux.js.org/tutorials/fundamentals/part-3-state-actions-reducers"&gt;https://redux.js.org/tutorials/fundamentals/part-3-state-actions-reducers&lt;/a&gt;&lt;/p&gt;

</description>
      <category>web3</category>
      <category>typescript</category>
      <category>react</category>
      <category>database</category>
    </item>
    <item>
      <title>Create An EVM Compatible Blockchain Bridge——DB3 Network build in public weekly update (20230213-20230218)</title>
      <dc:creator>xutweety</dc:creator>
      <pubDate>Sun, 19 Feb 2023 16:40:28 +0000</pubDate>
      <link>https://forem.com/db3network/evm-chain-settlement-design-db3-network-build-in-public-weekly-design-20230213-20230218-19in</link>
      <guid>https://forem.com/db3network/evm-chain-settlement-design-db3-network-build-in-public-weekly-design-20230213-20230218-19in</guid>
      <description>&lt;h2&gt;
  
  
  Brief intro
&lt;/h2&gt;

&lt;p&gt;We began to refactor our bill and gas system based, use the EVM chain to settle, and prepare for our network's economic model and the token release.&lt;/p&gt;

&lt;p&gt;Besides, more CLI and db3.js features are implemented, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;release a new &lt;a href="https://github.com/dbpunk-labs/db3/releases/tag/v0.2.8" rel="noopener noreferrer"&gt;version&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Feat/delete doc in CLI &lt;/li&gt;
&lt;li&gt;Create wallet/database/collection using &lt;a href="https://github.com/dbpunk-labs/db3.js" rel="noopener noreferrer"&gt;db3.js&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Brief pic about the &lt;a href="https://github.com/dbpunk-labs/db3/issues/203" rel="noopener noreferrer"&gt;EVM chain settlement design&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4pgaal923fhxrgixsqjm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4pgaal923fhxrgixsqjm.jpg" alt="db3-bridge" width="611" height="781"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Key PRs:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/dbpunk-labs/db3/pull/318" rel="noopener noreferrer"&gt;use u64 to store the balance of bill and credit&lt;/a&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Code:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db3&amp;gt;-$ new-db
 database address                           | transaction id 
--------------------------------------------+----------------------------------------------
 0xa15c58bf6ee75980b753396adb4d878129a47468 | qx7NsYyUOKondVHQjG0/itneIAujJofKsUc39Sy0Bpc= 
db3&amp;gt;-$ show-account
 address                                    | bills        | credits       | storage_used | mutations | session | nonce 
--------------------------------------------+--------------+---------------+--------------+-----------+---------+-------
 0x539a6192e4fcd61f53772a3284c7734bc0f6f1d6 | 0.000000 db3 | 10.000000 db3 | 102.00       | 1         | 0       | 0 
db3&amp;gt;-$ show-state
 name       | state 
------------+---------
 database   | 1 
 collection | 0 
 documemt   | 0 
 account    | 1 
 mutation   | 1 
 session    | 0 
 storage    | 102.00  
db3&amp;gt;-$ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Detail:
&lt;/h3&gt;

&lt;p&gt;Show network status in CLI; CLI could show the status of the following concept:&lt;/p&gt;

&lt;p&gt;DB-related concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;​   Database&lt;/li&gt;
&lt;li&gt;​   Collection: &lt;em&gt;aka 'table'&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;​   Document: &lt;em&gt;aka 'record'&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;​   Mutation: &lt;em&gt;aka 'write into / update'&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;​   Session: &lt;em&gt;aka ‘query’&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;​   Storage: the storage size of your data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Account-related concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;​   Address: &lt;/li&gt;
&lt;li&gt;​   Bills:  bills are generated by the consumption of data mutation and storage&lt;/li&gt;
&lt;li&gt;​   Credits: The credits are set by the initial number 10&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/dbpunk-labs/db3/pull/312" rel="noopener noreferrer"&gt;refactor the bill and gas system&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;refactor the bill and gas system, 1 MB data storage will cost &lt;em&gt;1DB3&lt;/em&gt;, you can experience it in our CLI tool.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/dbpunk-labs/db3/pull/319" rel="noopener noreferrer"&gt;Add EVM chain bridge&lt;/a&gt;
&lt;/h3&gt;




&lt;h2&gt;
  
  
  Key issues opened:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/dbpunk-labs/db3/issues/203" rel="noopener noreferrer"&gt;refactor the bill and gas system&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;We began to refactor our bill and gas system and prepare for an economic model and the token release.&lt;/p&gt;

&lt;p&gt;Help spread the work by giving us a star🌟 on &lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;​ &lt;/p&gt;

&lt;p&gt;​&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Helping Firebase Developers Integrate with Web3 and Build a Decentralized Social Data Model on the DB3 Network</title>
      <dc:creator>xutweety</dc:creator>
      <pubDate>Sat, 11 Feb 2023 14:33:38 +0000</pubDate>
      <link>https://forem.com/db3network/help-firebase-developer-to-cut-in-web3-and-build-a-decentralized-social-data-model-in-db3-network-3ken</link>
      <guid>https://forem.com/db3network/help-firebase-developer-to-cut-in-web3-and-build-a-decentralized-social-data-model-in-db3-network-3ken</guid>
      <description>&lt;p&gt;Currently, most of the web3 developers still start their developers's careers with exposure to web2's technology stack. For example, Solidity language is like the combination of C++ and Javascript. The node providers are often compared to Amazon Web Services (AWS). So finding a similar developing stack to cut in lets web2 developers seamlessly to get familiar with web3 quickly.&lt;/p&gt;

&lt;p&gt;Today we will use a decentralized firebase_&lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;DB3 Network&lt;/a&gt;, to help the developer to write data into a decentralized database. &lt;/p&gt;

&lt;p&gt;In the next 5 minutes we will walk you through the social dApp data model and show you how to build with DB3 Network.&lt;/p&gt;

&lt;p&gt;We have three core concepts: &lt;code&gt;database&lt;/code&gt;, &lt;code&gt;collection&lt;/code&gt;, &lt;code&gt;document&lt;/code&gt;. And we use these concepts to build a social data model. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxkq71azlj3bynvelhy5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxkq71azlj3bynvelhy5.png" alt="a simple social data model" width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create this data model in DB3 Network we can use the CLI and &lt;a href="https://github.com/dbpunk-labs/db3.js" rel="noopener noreferrer"&gt;db3.js&lt;/a&gt;. Let’s use the CLI for now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/dbpunk-labs/db3.git
cd db3 &amp;amp;&amp;amp; bash install_env.sh &amp;amp;&amp;amp; cargo build
# start localnet
cd tools &amp;amp;&amp;amp;  sh start_localnet.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use Console
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Start DB3 console
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(base) ~/Documents/GitHub/dbpunkslabs/db3   main  ./target/debug/db3 console

██████╗ ██████╗ ██████╗ 
██╔══██╗██╔══██╗╚════██╗
██║  ██║██████╔╝ █████╔╝
██║  ██║██╔══██╗ ╚═══██╗
██████╔╝██████╔╝██████╔╝
╚═════╝ ╚═════╝ ╚═════╝ 
@db3.network🚀🚀🚀
db3&amp;gt;-$ help
Usage: &amp;lt;COMMAND&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create a new database
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db3&amp;gt;-$ new-db
 database address                           | transaction id 
--------------------------------------------+----------------------------------------------
 0x3b3b3570100a7a02aa3efbad065e2eefb3f46bc7 | cg4flp3sIyt2MJuIqY1TRlFh8MnlSqNQfKnC7TxQnOU= 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Show database
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db3&amp;gt;-$ show-db --addr 0x1775b12ff28b48cdf66c2201d944c737514fe31f
 database address                           | sender address                             | releated transactions                        | collections 
--------------------------------------------+--------------------------------------------+----------------------------------------------+-------------
 0x3b3b3570100a7a02aa3efbad065e2eefb3f46bc7 | 0x72a2920c4f4b81a665aafb1f5f6e79e14bb9ce75 | 84Qs3vTO2Dp+ZCcIzeKWZ+5nGTycoCJRlAIh362KUjc= |  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add a collection to database
&lt;/h3&gt;

&lt;p&gt;Collection is aka data table.Then we create a &lt;code&gt;userinfo&lt;/code&gt; collection that records the social user information and set the indexers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db3&amp;gt;-$ new-collection 
--addr 0x1775b12ff28b48cdf66c2201d944c737514fe31f 
--name userinfo 
--index '{"id": 1,"name": "idx1","fields": [{"field_path": "name","value_mode": {"Order": 1}},{"field_path": "bio","value_mode": {"Order": 2}}]}'
send add collection done with tx
tQ4dU+46ZkvsM0s2pbjupWx2u8SLbRZmCkG6leG39Us=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db3&amp;gt;-$ show-collection --addr 0x1775b12ff28b48cdf66c2201d944c737514fe31f
 name     | index 
----------+-------------------------------------------------------------------------------------------------------------------------
 userinfo | {"name":"idx1","fields":[{"field_path":"name","value_mode":{"Order":1}},{"field_path":"bio","value_mode":{"Order":2}}]} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add a Document to the Collection
&lt;/h3&gt;

&lt;p&gt;Add a document (aka record) to the Collection. Here we add a user profile as a document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db3&amp;gt;-$ new-doc
    --addr 0x3b3b3570100a7a02aa3efbad065e2eefb3f46bc7 
    --collection-name userinfo 
    --documents '{"name": "Bob","age": 43,"bio": "a virtual person in Blockchain"}'
send add document done with tx
+O9cK2cHLexZQvIITk4OTm8SxBhq7Yz7g+xZYiionWo=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we will add more features to our CLl and db3.js. And we will explain the permission relationships helps to claim the ownership of your social data. And more features in a social dApp could be implementes: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Following/follower relationships&lt;/li&gt;
&lt;li&gt;Deleting posts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a web3 open source project, we are looking for your support. &lt;br&gt;
GitHub: &lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;Give us a star&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>career</category>
      <category>learning</category>
    </item>
    <item>
      <title>When you plan to build a dApp, you need DB3 Network</title>
      <dc:creator>xutweety</dc:creator>
      <pubDate>Fri, 13 Jan 2023 13:18:06 +0000</pubDate>
      <link>https://forem.com/db3network/when-you-plan-to-build-a-dapp-you-need-db3-network-2ohb</link>
      <guid>https://forem.com/db3network/when-you-plan-to-build-a-dapp-you-need-db3-network-2ohb</guid>
      <description>&lt;h1&gt;
  
  
  The Background
&lt;/h1&gt;

&lt;p&gt;Ethereum has defined the novel dapp data architecture successfully.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpvsaxgnoyaj2qb8eyu0v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpvsaxgnoyaj2qb8eyu0v.png" alt="Image description" width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The novel dapp data architecture has the following improvement:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;immutable&lt;/strong&gt;, when the protocol has been deployed, all the codes are immutable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;transparent&lt;/strong&gt;, the smart contract can be verified by anyone and any organization&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Permissionless&lt;/strong&gt;, everyone can use the protocol in the world&lt;br&gt;
but &lt;strong&gt;Ethereum has some limitations&lt;/strong&gt; e.g. scalability problems and high storage cost and &lt;strong&gt;it can not cover the requirement of the storage-heavy dapps&lt;/strong&gt;. So a hybrid data architecture so called web2.5 is used for the storage-heavy dapps.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ugmago0ewk6q8kbp7g2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ugmago0ewk6q8kbp7g2.png" alt="Image description" width="682" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The problem in the above is the hybrid data architecture will break the improvement that the web3 native application data architecture brings to us and the db3 network is trying to resolve the problem&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxsuyczx18bkdrsqu4fj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxsuyczx18bkdrsqu4fj.png" alt="Image description" width="628" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What’s the &lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;DB3 Network&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flah8lkh5gzsgioiouwrs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flah8lkh5gzsgioiouwrs.png" alt="Image description" width="628" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;DB3&lt;/a&gt; is a community-driven layer2 decentralized database network with the following core features:&lt;/p&gt;

&lt;h2&gt;
  
  
  Infinite Storage Space
&lt;/h2&gt;

&lt;p&gt;Scalability is the key to the web3 explosion, &lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;db3&lt;/a&gt; will use the following strategies to achieve web3 scale. PC can meet the minimum system requirements so everyone can join the &lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;db3 network&lt;/a&gt; to provide storage space. Using dynamic sharding to achieve scale out. when a storage shard chain has not enough space to store mutation, it will split itself into two subchains.Using cold data archive to recycle storage space. history cold blocks and cold state data will be archived to FileCoin and the storage node will always has storage space to store new data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Blazed Fast and Provable On-chain Query
&lt;/h2&gt;

&lt;p&gt;Currently, decentralization means bad performance but &lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;db3&lt;/a&gt; is trying to make a big improvement in performance. Merkdb 2 is the storage engine of db3 network and it not only has high performance but also the fast-proof generation.Geo distribution, the nodes in every storage shard are geo-distributed and the clients can execute querys against the nearest storage node. Query session, the first decentralized query protocol to resolve performance and incentive perfectly&lt;/p&gt;

&lt;h2&gt;
  
  
  Crypto Native Data Ownership
&lt;/h2&gt;

&lt;p&gt;In the decentralized network, only the private key owners can update their data and they can keep privacy by encrypting their data with the public key&lt;/p&gt;

&lt;h2&gt;
  
  
  On-chain Programmable
&lt;/h2&gt;

&lt;p&gt;Dapp developers can develop data processing contracts and deploy them to the &lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;db3 network&lt;/a&gt; just like developing data backend in web2&lt;/p&gt;

&lt;h2&gt;
  
  
  Ethereum Guarded Security
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;DB3 network&lt;/a&gt; is a layer2 network on Ethereum and all the assets are guarded by Ethereum.&lt;/p&gt;

&lt;h2&gt;
  
  
  db3.js-Developer-friendly SDK
&lt;/h2&gt;

&lt;p&gt;db3.js is the db3 network 2 javascript API and you can write and query JSON documents against the db3 network with db3.js and you can combine the web3.js and db3.js to build a fully decentralized storage-heavy application. the web3 developers can use this API to put and get documents with the db3 miner node directly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foc5eh7x6jui8m9jkaw1o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foc5eh7x6jui8m9jkaw1o.png" alt="Image description" width="529" height="263"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;request.onsuccess = function () {
  console.log("Database opened successfully");
  const db = request.result;
  // 1
  const transaction = db.transaction("cars", "readwrite");
  //2
  const store = transaction.objectStore("cars");
  const colourIndex = store.index("cars_colour");
  const makeModelIndex = store.index("colour_and_make");
  //3
  store.put({ id: 1, colour: "Red", make: "Toyota" });
  store.put({ id: 2, colour: "Red", make: "Kia" });
  store.put({ id: 3, colour: "Blue", make: "Honda" });
  store.put({ id: 4, colour: "Silver", make: "Subaru" });
  //4
  const idQuery = store.get(4);
  const colourQuery = colourIndex.getAll(["Red"]);
  const colourMakeQuery = makeModelIndex.get(["Blue", "Honda"]);
  // 5
  idQuery.onsuccess = function () {
    console.log('idQuery', idQuery.result);
  };
  colourQuery.onsuccess = function () {
    console.log('colourQuery', colourQuery.result);
  };
  colourMakeQuery.onsuccess = function () {
    console.log('colourMakeQuery', colourMakeQuery.result);
  };
  // 6
  transaction.oncomplete = function () {
    db.close();
  };
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The overview of &lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;db3 network&lt;/a&gt; architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fewis00x0r7gcjeu0tjqh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fewis00x0r7gcjeu0tjqh.png" alt="Image description" width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why does &lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;DB3 Network&lt;/a&gt; focus on the storage-heavy dapps
&lt;/h2&gt;

&lt;p&gt;image&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xo8epkhmfosifh2tr22.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xo8epkhmfosifh2tr22.png" alt="Image description" width="586" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The more dynamic data the dapp used , the more users that the dapp will onboard.So we think the storage-heavy dapps are the future of web3&lt;/p&gt;

&lt;h2&gt;
  
  
  Other Decentralized Databases
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;the graph&lt;/strong&gt;&lt;/em&gt;, a decentralized on-chain indexer&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Locutus&lt;/strong&gt;&lt;/em&gt;, a decentralized key-value database&lt;br&gt;
&lt;em&gt;&lt;strong&gt;ceramic network&lt;/strong&gt;&lt;/em&gt;, a decentralized data network that brings unlimited data composability to Web3 applications&lt;br&gt;
kwil, the first permissionless SQL database for the decentralized internet&lt;br&gt;
&lt;em&gt;&lt;strong&gt;spaceandtime&lt;/strong&gt;&lt;/em&gt;, a decentralized data Warehouse&lt;/p&gt;

&lt;p&gt;if you are interested in the db3 network, &lt;strong&gt;please give us a star on &lt;a href="https://github.com/dbpunk-labs/db3" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>watercooler</category>
      <category>gratitude</category>
      <category>welcome</category>
    </item>
    <item>
      <title>How to store NFT metadata decentralized and dynamically</title>
      <dc:creator>xutweety</dc:creator>
      <pubDate>Tue, 20 Dec 2022 08:01:28 +0000</pubDate>
      <link>https://forem.com/xutweety/how-to-store-nft-metadata-decentralized-and-dynamically-5203</link>
      <guid>https://forem.com/xutweety/how-to-store-nft-metadata-decentralized-and-dynamically-5203</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q3CcLlsi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ic7dw43q09vow3g7hjw1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q3CcLlsi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ic7dw43q09vow3g7hjw1.png" alt="The metadata of a dNFT representing a property can change to reflect maintenance history, past sales, etc. &amp;lt;br&amp;gt;
" width="880" height="631"&gt;&lt;/a&gt;&lt;br&gt;
image from &lt;a href="https://blog.chain.link/what-is-a-dynamic-nft/"&gt;https://blog.chain.link/what-is-a-dynamic-nft/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It is difficult for the metadata in dNFT(dynamic NFT) to achieve “decentralization” and “dynamic change” at the same time.&lt;/strong&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Decentralized metadata storage
&lt;/h1&gt;

&lt;p&gt;About 48% of NFT (most NFTs are static) metadata is decentralized and stored on IPFS. The format suffix is &lt;code&gt;ipfs/your_collection_file_hash/tokenid&lt;/code&gt;, where &lt;code&gt;your_collection_file&lt;/code&gt; refers to the NFT collection, where &lt;code&gt;tokenid&lt;/code&gt; is a number, such as “26”. An example of such a project is Bored Ape Yacht Club, the metadata of which is stored in IPFS, although the BaseURI used for IPFS can be changed by the contract owner.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dNsQUoTm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sj9v7ohouyff57xcu474.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dNsQUoTm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sj9v7ohouyff57xcu474.png" alt="The metadata of Bored Ape NFT is stored in IPFS, and it records multiple attributes, fur, mouth, etc. image from author" width="880" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suppose the platform wants to provide NFT customization capabilities and put metadata in decentralized storage. In that case, developers need to exhaust all possible combinations of attributes, put all the varieties of metadata on IPFS, and then index according to the combination of attributes to find the tokenURI in IPFS to get the metadata.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OyzFrlDb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i5fvq2e0va4lcufzvhtd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OyzFrlDb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i5fvq2e0va4lcufzvhtd.png" alt="The picture demonstrated the relationship between the links. image from author." width="880" height="551"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The disadvantages of this approach are:
&lt;/h2&gt;

&lt;p&gt;There are many metadata combinations, leading to much storage cost in advance. You have to store them all in advance.&lt;/p&gt;

&lt;p&gt;If the platform wants to add a Smartglasses option to the feature of Glasses, or when it provides the ability to change dynamically, it can change the metadata information in the NFT about the game level and other metadata information in the NFT according to the goals of the World Cup during a match. At this point, the timeliness requirements for metadata changes are higher. For example, this dynamic change almost equals replacing a new NFT, and the cost of changing NFT metadata will rise sharply.&lt;/p&gt;
&lt;h1&gt;
  
  
  Dynamically update first
&lt;/h1&gt;

&lt;p&gt;The second method is to abandon the decentralized metadata storage and only put the ownership on the Chain to ensure timely and rapid dynamic changes. Some projects generate metadata through a centralized server, and the metadata information of the customized NFT will be combined and generated in a centralized manner.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--stAHNI_R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0cmnpgw69li3fwier8b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--stAHNI_R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0cmnpgw69li3fwier8b.png" alt="image from author" width="880" height="535"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To be able to display different houses in 2022 and 2027, NFT minter should first put other roofs on the Chain, store metadata off the Chain, and the URL of a centralized service to do the correlation, pointing to one of them in 2022, and replacing it in 2037 to another one.&lt;/p&gt;

&lt;p&gt;However, they store metadata on their central storage, and these servers can fail in the blink of an eye, costing NFT owners millions worldwide.&lt;/p&gt;

&lt;p&gt;More importantly, it isn’t easy to guarantee that such storage will not be tampered with. Especially for some game NFTs, their value does not lie in the displayed pictures but in the information that is crucial in the game, such as force values, levels, etc. This information is stored in metadata. It is impossible to guarantee that only the owner of the NFT owner who can change the metadata based on centralized storage.&lt;/p&gt;

&lt;p&gt;And when the metadata storage is separated from data on the Chain, the dynamic metadata history does not leave traces on the Chain, and the two are unrelated, so it isn’t easy to carry out practical analysis and insight.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--avur-LLL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AmHFs60y_e5cRjdRPP6BKrA.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--avur-LLL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AmHFs60y_e5cRjdRPP6BKrA.webp" alt="The history of the house,image from author" width="880" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Currently, only the first two columns of data are kept on-chain, which you can see directly from platforms like OpenSea. But you only know that the price is increasing over time, but you need to understand why. The last data column is in the platform’s centralized server, which is unreliable. For example, a sharp price increase in 2029 is due to the repair of a new roof — the information about this is in the third column of metadata. Because the metadata is changing and is not stored on the Chain, it may be tampered with, so you cannot know, nor is it challenging to analyze and understand what a more reasonable price in 2037 is. These problems may lead to a poor display experience of dNFT in the NFT trading market, making it difficult for dNFT to circulate and prosper in the secondary market.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8TfPJ6UI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fzppscxi0c15osopy4oq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8TfPJ6UI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fzppscxi0c15osopy4oq.gif" alt="image from https://i.ibb.co/8NcyKwh/dyanmic.gif" width="880" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, in OpenSea, a dNFT that changes with the daily sunshine conditions rotates the animation every 8 hours, the change history of metadata is not presented on the website, and the dynamic feature is completely invisible when you first enter it. You have no way of knowing this is dynamic.&lt;/p&gt;
&lt;h1&gt;
  
  
  Put all the things on the Chain.
&lt;/h1&gt;

&lt;p&gt;Therefore, it is best to put all metadata, images, transaction information, etc., on the Chain and can add the metadata and change it conveniently and dynamically. Your signature should perform the changes, and the NFT platform as an intermediary minimizes the direct touch of data (reading and writing, caching, etc.).&lt;/p&gt;
&lt;h1&gt;
  
  
  DB3 network
&lt;/h1&gt;

&lt;p&gt;Here, let me introduce the DB3 network, a decentralized storage solution that adopts the key-value storage paradigm and has advanced database properties, such as mutation and programmability.&lt;/p&gt;
&lt;h2&gt;
  
  
  Change metadata easily based on a decentralized storage.
&lt;/h2&gt;

&lt;p&gt;DB3 can support convenient CRUD-like operations, insert, update, read and delete stored data. This is easy to achieve for centralized storage, but it is challenging to accomplish for decentralized storage. The reason is that the update operation conflicts with the immutable characteristics of the blockchain. But in use cases such as the dynamic NFT mentioned above, immutable storage is important from a security point of view, but it limits the number of possible applications (such as the evolutionary ability of NFT).&lt;/p&gt;

&lt;p&gt;A mutation is defined in the DB3 network as our core concept. All operations on data modification are defined as mutation. You can use mutation to insert, update and delete data. For example, you can easily complete the data renewal when you want to modify roof color meatada.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;put house roofcolor offwhite
submit mutation to mempool done!
&amp;gt;get house roofcolor
roof -&amp;gt; offwhite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the same time, mutation can perform data update operations, and the other three: insert/update/delete and the hash returned by these operations will be submitted to the block.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XFa3jnlL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ad2gwhppifa8aerltgze.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XFa3jnlL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ad2gwhppifa8aerltgze.png" alt="the operation is recorded into blocks, image from author" width="880" height="701"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Analyze metadata history onchain&lt;br&gt;
Every metadata change of dNFT will be recorded on the chain like a snapshot. At the same time, because we have optimized the efficiency of our storage engine, we can achieve high-performance queries, not inferior to the web2 database. Therefore, in the future, analysis of dNFT will be very easy to read and display a more credible metadata history.&lt;/p&gt;

&lt;h2&gt;
  
  
  Claim metadata ownership
&lt;/h2&gt;

&lt;p&gt;Secondly, the description information of dNFT will be stored in a concept similar to the “table” in web2. Since the metadata defines the asset, securing metadata is as important as securing ownership. The operation and modification of this table need to obtain the user’s permission, which is completely controlled by the user, ensuring the ownership of dNFT. The centralized service should barely touch metadata.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ca_u4Rbp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wq8om57yh4nuzkp2gtdb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ca_u4Rbp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wq8om57yh4nuzkp2gtdb.png" alt="owernship in DB3network" width="880" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our &lt;a href="https://github.com/dbpunk-labs/"&gt;Github&lt;/a&gt;：&lt;/p&gt;

&lt;p&gt;Browse some design docs;&lt;br&gt;
Start coding from &lt;a href="https://github.com/dbpunk-labs/db3/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22"&gt;&lt;em&gt;goodfirstissue&lt;/em&gt;&lt;/a&gt;;&lt;br&gt;
Discuss with us according the &lt;em&gt;&lt;a href="https://github.com/dbpunk-labs/db3/issues?q=is%3Aissue+is%3Aopen+label%3Adiscussion-required"&gt;WIPissue&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>nft</category>
      <category>blockchain</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
