Helping Firebase Developers Integrate with Web3 and Build a Decentralized Social Data Model on the DB3 Network

xutweety

xutweety

Posted on February 11, 2023

Helping Firebase Developers Integrate with Web3 and Build a Decentralized Social Data Model on the DB3 Network

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.

Today we will use a decentralized firebase_DB3 Network, to help the developer to write data into a decentralized database.

In the next 5 minutes we will walk you through the social dApp data model and show you how to build with DB3 Network.

We have three core concepts: database, collection, document. And we use these concepts to build a social data model.

a simple social data model

To create this data model in DB3 Network we can use the CLI and db3.js. Let’s use the CLI for now.

Build

git clone https://github.com/dbpunk-labs/db3.git
cd db3 && bash install_env.sh && cargo build
# start localnet
cd tools &&  sh start_localnet.sh
Enter fullscreen mode Exit fullscreen mode

Use Console

Start DB3 console

(base) ~/Documents/GitHub/dbpunkslabs/db3   main  ./target/debug/db3 console

██████╗ ██████╗ ██████╗ 
██╔══██╗██╔══██╗╚════██╗
██║  ██║██████╔╝ █████╔╝
██║  ██║██╔══██╗ ╚═══██╗
██████╔╝██████╔╝██████╔╝
╚═════╝ ╚═════╝ ╚═════╝ 
@db3.network🚀🚀🚀
db3>-$ help
Usage: <COMMAND>
Enter fullscreen mode Exit fullscreen mode

Create a new database

db3>-$ new-db
 database address                           | transaction id 
--------------------------------------------+----------------------------------------------
 0x3b3b3570100a7a02aa3efbad065e2eefb3f46bc7 | cg4flp3sIyt2MJuIqY1TRlFh8MnlSqNQfKnC7TxQnOU= 
Enter fullscreen mode Exit fullscreen mode

Show database

db3>-$ show-db --addr 0x1775b12ff28b48cdf66c2201d944c737514fe31f
 database address                           | sender address                             | releated transactions                        | collections 
--------------------------------------------+--------------------------------------------+----------------------------------------------+-------------
 0x3b3b3570100a7a02aa3efbad065e2eefb3f46bc7 | 0x72a2920c4f4b81a665aafb1f5f6e79e14bb9ce75 | 84Qs3vTO2Dp+ZCcIzeKWZ+5nGTycoCJRlAIh362KUjc= |  
Enter fullscreen mode Exit fullscreen mode

Add a collection to database

Collection is aka data table.Then we create a userinfo collection that records the social user information and set the indexers.

db3>-$ 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=
Enter fullscreen mode Exit fullscreen mode
db3>-$ show-collection --addr 0x1775b12ff28b48cdf66c2201d944c737514fe31f
 name     | index 
----------+-------------------------------------------------------------------------------------------------------------------------
 userinfo | {"name":"idx1","fields":[{"field_path":"name","value_mode":{"Order":1}},{"field_path":"bio","value_mode":{"Order":2}}]} 
Enter fullscreen mode Exit fullscreen mode

Add a Document to the Collection

Add a document (aka record) to the Collection. Here we add a user profile as a document.

db3>-$ 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=
Enter fullscreen mode Exit fullscreen mode

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:

  • Following/follower relationships
  • Deleting posts.

As a web3 open source project, we are looking for your support.
GitHub: Give us a star

💖 💪 🙅 🚩
xutweety
xutweety

Posted on February 11, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related