This will get you up to speed with the basics of working with Decentralized Web Nodes (DWNs) and DIF's DWN Community Node, powered by TBD and Google Cloud. This includes a minimal CLI project and additional guidance to get you started.
A DWN is a decentralized personal and application data storage and message relay node. Users may have multiple nodes that replicate their data between them.
DWNs provide the following benefits:
DWNs follow an open standard; see the DIF Decentralized Web Node specification. DIF plays a vital role in addressing these challenges through standardization and education, paving the way for a future Web where privacy and data sovereignty are paramount.
TBD and Google Cloud have partnered to enable DIF’s DWN Community Node. The goal is to make it easy for builders to get started with next generation web infrastructure.
The Community Node is a reliable sandbox for staging, pre-production, or testing -- not production use.
You can connect to the Community Node easily by passing the endpoint when calling Web5.connect()
, as shown below.
For simplicity, this sample uses TBD's @web/api
package, which handles the details of interacting with DWNs. Because this conforms to the DWN spec, you may use a different library or write your own to interact with DWNs.
By default, the @web5/api
package connects to TBD's DWN instance. You can configure this code to connect to other instances, such as your own self-hosted instance or DIF's Community Node.
We'll start with a basic DWN command line example, which will use the default (TBD's) DWN node, and then update it to use DIF's Community Node.
git clone https://github.com/decentralized-identity/dwn-cli-sample.git
cd dwn-cli-sample
npm install
npm run build
./bin/run.js create-did
Output will look like:
Created DID: did:dht:43ffbao7fxkhofcxpody87dz74cp5ynx8bsed4iudtzqk7gimewy
./bin/run.js store-data "hello world"
Output will look like:
Record ID: bafyreih4rqmu4jztwoews26onwda3y7p4gfguevke2cxhvtvmul73bl4v4
./bin/run.js all-data
Output will look like:
==============Document list==========
1. bafyreih4rqmu4jztwoews26onwda3y7p4gfguevke2cxhvtvmul73bl4v4
./bin/run.js retrieve-data bafyreih4rqmu4jztwoews26onwda3y7p4gfguevke2cxhvtvmul73bl4v4
Output will look like:
============Record Data=================
Author: did:dht:43ffbao7fxkhofcxpody87dz74cp5ynx8bsed4iudtzqk7gimewy
Content: hello world
To connect to the community node, simply pass https://dwn.gcda.xyz to the dwnEndpoints
array as shown below:
const {did, web5} = await Web5.connect({
didCreateOptions: {
dwnEndpoints: ['https://dwn.gcda.xyz'], // User provides google's community DWN instance
},
registration: {
onSuccess: () => {
// Registration succeeded, set a local storage value to indicate the user is registered and registration does not need to occur again.
},
onFailure: (error) => {
// Registration failed, display an error message to the user, and pass in the registration object again to retry next time the user connects.
},
},
})
By default, when you call Web5.connect()
it will use the bootstrap DWN nodes included which allow people to reach you via your DID.
You may want to run a DWN server just for you, or as a public service for you and your friends and family. DWNs can be as simple as a docker image or a node process running somewhere.
DWN-servers can run anywhere you can run node.js or docker. http and websocket need to be available to the DWN server. See below for some suggestions.
For additional details about configuration settings for privacy, data storage, and network connectivity, see TBD's recommendations.
You can run an instance on the render.com service:
You can run a DWN-server on your local machine or home server and expose it to the internet using ngrok.
First, install ngrok
Then run:
docker run -p 3000:3000 -v myvolume:/dwn-server/data ghcr.io/tbd54566975/dwn-server:main
## in another terminal:
ngrok http 3000
Cloudflare has a tunnel service that you can use to expose your DWN server to the internet, if you run it on a server at home. With cloudflared installed, run the following commands:
git clone https://github.com/TBD54566975/dwn-server.git
cd dwn-server
npm install
npm run server
## in another terminal:
cloudflared tunnel --url http://localhost:3000