Building a Site on SAFE in Just Three Commands

Josh Wilson
Sep 19 · 4 min read

With the release of the new CLIs, here’s a small guide to help you make use of the CLI and build a site on the SAFE Network in three simple commands.

But first, let’s get you set up!

What you’ll need before we start;

Helpfully, we’ve got a guide on how to download both of these, plus user guides for both SAFE_CLI and SAFE_auth that we’d recommend you have handy as they give you a detailed overview of what functionality each give you. Once you have the SAFE_auth daemon running locally (this is in the guide too), we’re ready to begin!

$ safe auth will enable the authorisation and save the authentication locally for you. It should look something like this…

Command One: Uploading data

So now, let’s say you have a local folder mysite that contains index.html and css/styles.css so it’s not ugly.

$ safe files put -r mysite/

This will upload your folder to the SAFE Network. The / at the end is important to set the root of your newly created FilesContainer to be mysite (and not have mysite as a folder within it). You can read more about this in the safe-cli User Guide 2.

It will in return, print out some info about your new files on the network. The Files Container URL is important and we’ll need it for the next step…

Command Two: Creating a Public Name

The SAFE Network uses a distributed NRS to allow you to register URLs (but without any third party). NRS means Name Resolution System and the easiest way to think about it is how SAFE lets you have human-readable urls.

To do that and register a site, such as thesite:

$ safe nrs create thesite -l "<link to FilesContainer URL>?v=0"

?v=0 is needed here to specify a version to point to. The SAFE Network principles note that all public data must be versioned. And this way, we can easily track any/all changes to a Public Name.

And now, you can check your site on the network via;

$ safe cat safe://thesite/index.html

Command Three: Updating your Files

The SAFE Network distinguishes between updating a FilesContainer, and updating an NRS Name. The latter, must always be versioned (as we saw above).

When you have changes to your site, you can update your NRS using the files api thus:

$ safe files sync -r ./mysite/ safe://thesite -u -d -r

-u here updates the corresponding NrsContainer as well as the FilesContainer, so your changes will be reflected at safe://thesite. -d signifies that any deleted files will be deleted in the next version of the containers, too. -r is again, to sync recursively.

And now, if you access safe://thesite/index.html, you’ll see your changed files:

Not only can you update your site easily, but inherent in the SAFE Network is versioning. What this means is that you can actually access older versions of a site via the version query param: $ safe cat “safe://thesite?v=0”, will show you your first content, for example. Pretty neat huh?

So you’ve played around with these Command Lines. But what if you want to actually see your site in action? we have a browser proof of concept available for download that works with the above CLIs and of course, Vaults too. However, please note this only works for Linux and Mac just now, with Windows to follow soon.

So after this, you’re probably thinking: why doesn’t the internet today do this?! Why do I have to faff around with domain registrars, pay money and not own my stuff. Why do I need a server?

We agree, hence why we’re one a single mission to build the SAFE Network. A permissionless network that removes faff, servers and allows you to just start developing. Why not join us?

safenetwork

Stories from around the SAFE Network

Josh Wilson

Written by

safenetwork

Stories from around the SAFE Network

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade