LFS Series — Introducing “Hubs” & The dWeb CLI

Now that you have seen all that dWeb 3.0 has to offer, it’s time to start playing around and creating dWeb-based services. The all-new dWeb CLI makes all this possible. dWeb’s CLI handles the entire dHub daemon installation process for you, so that you can focus on development and publishing dWeb-based experiences without any complexities. To install dWeb CLI and startup the dHub daemon in the background, do the following:

```

npm install @dhub/cli -g

dweb daemon start

```

- Then check the daemon status like so:

```

dweb daemon status

```

If everything is running smoothly, the fun can begin!

==== GETTING INFORMATION ABOUT “HUBS”

“Hubs” are dWeb data structures and you can retrieve information about a single Hub or a group of Hubs, using their dWeb network addresses, by running the following:

```

dweb info [address1, address2]

```

==== CREATING HUBS

You can easily create a dDrive or a dTree by running the following commands:

- Creating a dDrive

```

dweb create drive

```

- Create a dTree

```

dweb create dtree

```

Either command will spit out the dWeb network address for both structures.

==== MANAGING DDRIVES

dWeb CLI allows you to manipulate your own dDrives and view the content of remote dDrives. Here are a few examples:

- List the entries of a given dDrive URL

```

dweb drive ls {url}

```

- Create a directory in a dDrive

```

dweb drive rmdir {url}

```

- Remove a directory in a dDrive

```

dweb drive rmdir {url}

```

- Output the content of a given dDrive URL

```

dweb drive cat {url}

```

- Write a file at the given dDrive URL

```

dweb drive put {url} [content]

```

- Remote a file or (if — recursive) a folder at the given dDrive URL

```

dweb drive rm {url}

```

- Compare two folders in your local file system or in dDrives. Can optionally commit ( — commit) the difference

```

dweb drive diff {source_path_or_url} {target_path_or_url}

```

- Continuously sync changes between two folders in your local filesystem or in dDrives

```

dweb drive sync {source_path_or_url} [target_path_or_url]

```

- Broadcast a dDrive over HTTP (localhost)

```

dweb drive http {url}

```

==== MANAGING DTREES

dWebCLI allows you to manipulate your own dTrees or search remote dTrees. Below is a few usage examples:

- List the entries of the given dTree URL

```

dweb tree ls {url}/key

```

- Get the value of an entry (key) of the given dTree URL

```

dtree tree get {url}/key

```

- Set the value of an entry on the given dTree URL

```

dweb tree put {url}/key [value]

```

- Delete an entry at the given dTree URL

```

dweb tree del {url}/key

```

- Delete an entry at the given dTree URL

```

dweb tree del {url}/key

```

==== SEEDING DATA STRUCTURES

You can seed or unseed individual dWeb addresses or a group of addresses using the `seed` or `unseed` commands, like so:

- Seeding:

```

dweb seed [address1, address2]

```

- Unseeding:

```

dweb unseed [address1, address2]

```

==== CASTING DATA TO OTHERS

In a previous post, I outlined the new dCast utility (https://npmjs.com/package/dcast) which allows peers to exchange data over an encrypted one-to-one pipe. You can cast data to another peer, using a passphrase and the data you want to share. An example of this would look like this:

- On sending device:

```

cat let-freedom-stream.txt | dweb cast “secret”

```

- On receiving device:

```

dweb cast “secret” > ./let-freedom-stream.txt

```

==== PIECING IT ALL TOGETHER

Using the methods I just showcased, lets create a dTree, and insert the code representation of a profile image and the data from a post, within a dTree and seed it to others.

```

dweb create dtree

// Check for entry

dweb ls dweb://<address>/profile-image

// If it doesn’t exist, lets create it

cat picture-of-me.png | dweb put dweb://<address>/profile-image

// Seed it

dweb seed dweb://<address>

```

- Keep in mind that we are now seeding a dTree (a distributed binary tree-based database) that has a single entry:

```

KEY VALUE

====== ===============

profile-image <code from image file>

```

- On another computer, lets live sync the dTree:

```

dweb seed dweb://<address>

```

- On the original computer where the dTree was created, lets add a post:

```

dweb dtree put dweb://<address>/post/1 {postData: <data>, timestamp: <timestamp>, drive: <address>}

```

Since the remote computer is seeding this data already, it will have access to our newly created post nearly instantaneously. In this way, dTrees can be used as our Local Layer and a DHT could be used as the Remote Layer. Considering a dTree allows us to utilize a key-value store at the Local Layer, we can interface with a DHT (a multi-writer key-value store) much more efficiently.

==== DWEB APPLICATION-BASED INTEGRATION

dBrowser will expose an API that allows dWeb-based applications to interact with dWeb CLI directly, so that they can easily create, traverse and seed dWeb-based data structures without any hang-ups. This means a social network like dSocial could easily power itself without a blockchain, or even a DHT (we’re not that brave yet) by simply traversing a user’s Local Layers. For now though, a DHT bridges every Local Layer and combines them all in a single Remote Layer which makes life much easier on our applications.

==== DESKTOP APPLICATION INTEGRATION

Any desktop application that is Node + Electron-based can interface with dHub at runtime, using the all new “dweb-electron-runtime” module (https://npmjs.com/package/dweb-electron-runtime). dWeb CLI can be interfaced with directly using “spawn.”

So, is there a development kit that brings all of this together or one that can be used to develop React Native-based mobile applications for iOS and Android? In our next post we discuss the all-new dWeb SDK and new “random access” storage providers and networking tools for cross-platform development.

====

WHAT’S NEXT?

Learn how you can build cross-platform dWeb-powered applications using the all-new dWeb SDK.

====

The creators of the #dweb and the world’s first decentralized and censorship-resistant social network. We’re about to #DecentralizeEverything.