How to launch Swarm for dapp testing

AnnMargaret Tutu
9 min readFeb 9, 2017

Recently, I’ve been getting my feet wet with developing decentralized applications (dapps) using emerging tools I think everyone should try out.

Ether’s a little bit different from predecessor cryptocurrencies Bitcoin because it comes with it’s own platform for developers, called Ethereum, comprised of:

  • a decentralized virtual machine that runs “smart contracts” for the global base blockchain
  • a peer to peer, multi-protocol IDE developer tools to build dapps that administer custom tokens, manage accounts and transactions, and execute immutable contracts that take banking, commerce, fundraising, and democracy to a whole new level

Ethereum empowers and incentivizes folks, like you and me, to share knowledge, create equity and build wealth, all at the same time; a secure, coset-effective solution for developing with purpose while helping your end users to get paid.

OOP skills still have value because the high-level contract-oriented languages used to program contract logic closely resemble popular languages (JavaScript, Python, Go); Solidity being the most common because it looks so much like JS.

Contracts — backend applications that operate autonomously, unbiasedly, and indefinitely unless programmed to destruct after a set time — facilitate “transactions” to and from end users, and do so while mitigating the risk of fraud, censorship, or third-party interference.

Truly remarkable.

A growing ecosystem for web 3.0 projects

Naturally, over the past couple of years, Ethereum has developed to include an emerging ecosystem of web 3.0 companion technologies — a Wallet, its own browser Mist, the Whisper package for messaging dapps and, most recently, a decentralized data storage called Swarm — to push the vision of the serverless computer forward, expand use cases, and bring the blockchain to industries and sectors that need this sort of unbiased, secure intervention the most.

Here’ an illustration of what web 3.0 coin the “holy trinity” (Ethereum, Whisper and Swarm) for dapp development:

+ Source: Fast Company

So, what is Swarm exactly, and how does it work?

The purpose and functionality of Whisper seems intuitive to me (at its core, it’s a messaging package) but Swarm warrants more explanation, I think.

Pulling from the days of Napster, here’s how I understand it: a peer to peer, low latency, data sharing network that enables developers to host and store resources (data and static files — the HTML, CSS, JS) on server-like nodes, and make those resources accessible to end users at a hash address.

No actual server needed.

I think Swarm has a lot of potential to make file sharing and data storage the most transparent and cost-effective it’s ever been for developers. The distributed design leverages the power of peer connections to lighten the load of deploying dapps — dapps that can grow indefinitely (like the network, itself) — with zero downtime. DDOS-resistant.

All the while, end users have a fiscal incentive (earning ether) to post new resources.

It’s a dope, win-win for all type of situation. Not to mention, self-sustaining.

Note: developers do need to consider data sensitivity when choosing to go this route. Data cannot be deleted once persisted to a hash address and the Ethereum team advises against sharing any resources that you might want to remove later on.

Like Bitcoin, Swarm has a TestNet to help developers troubleshoot these sorts of issues with proof of concept dapps and debug. In the next sections, I’ll walk you through launching the Swarm TestNet and using gateways to browse web 3.0 dapps.

Launching the Swarm TestNet for the First Time

I found launching a Swarm TestNet instance to be a great learning experience, but did experience some hiccups (inconsistencies with version documentation, getting used to GO, etc.) because everything seems to be in rapid development mode.

Ethereum’s github account has loads of really helpful documentation, though, to help you get started with linking to other ecosystem technologies. I’m hoping this tutorial helps others feel more comfortable with getting started with Swarm.

Step One: Setting up go-ethereum

If you haven’t already, please download the Go language. I wrote a tutorial to help with installing Go and setting up a work station for Mac, here.

Steps for quickly bashing through this:

  • create a Go workspace directory, preferably in the HOME directory
  • define the $GOPATH env var to point to this directory
  • and echo this path to your startup script
  • create workspace directories (nest, top down: src, github.com, ethereum)
  • cd into ethereum and clone go-ethereum from GitHub
  • cd into go-ethereum and grab all the project dependencies

Here’s what the terminal should look like when you accomplish this:

Step Two: Compile Geth and Swarm packages

Next we want to compile the necessary packages: Geth, to launch our node and Swarm, the file sharing network.

  • run “go install -v ./cmd/geth”
  • then, run “go install -v ./cmd/swarm”

You should see a long run down of all the dependencies for both packages.

It should look like this:

(packages compiling)

In the background, the go install command creates our Geth and Swarm binaries in the workspace’s bin directory (located at ~/go/bin).

To ensure that everything’s chill, cd into your bin and list the subfolders (you should see geth and swarm). You might also want to check that you have the latest version of Swarm:

(everything’s good, like it oughta be)

Step Three: Make a data directory and a Swarm TestNet account

Now, the fun begins.

To proceed, the first thing we want to do is create a data directory for the geth node we’re about to launch. I’m going to put my data directory on the Desktop (because I put everything on my desktop, if I can help it).

Once this is set, next steps would be:

  • set up a geth account with two options: (1) testnet (indicating this is a TestNet account); (2) datadir (pointing to the data directory you just created)
  • add account new at the end
  • choose a password when prompted
(new geth account)

Once you choose a password for your new account, Geth administers an address (a handle, basically). You’ll want to save that address somewhere safe for easy access later.

Step Four: Launch a Geth Node

Next, we want to launch a node. Again we bash the get binary, but add one more option this time: fast. This means we want a fast syncing download instead of waiting for the whole TestNet.

Once your node starts up, your terminal should look like this:

(geth node running, blockchain downloading)

After a little bit, you’ll notice that your testnet folder auto-generates in your data directory, with a keystore directory. The address/handle provided earlier at Geth account signup points to this file in your keystore.

(TestNet key)

Step Five: Start Swarm TestNet

Now, in a new terminal tab, we want to start up Swarm. To do this, we bash the swarm binary (same deal as with the geth binary) with three options: (1) bzzaccount (your geth account address);

(2) the path to your datadir;

(3) ethapi (the path pointing to a file called geth.ipc in your testnet directory.

You’ll then be prompted to provide your password you chose earlier when setting up your Swarm account, and then you’re good to go on that front. Swarm should start loading.

(IPC endpoint opening)

Since this is a p2p network, you’ll have to wait a few to connect with peers. When you do make connections, it your terminal window should look something like this:

(peer connections for swarm instance)

And by now, the blockchain should be fully downloaded to your data directory, which means we’re ready to move to the browser.

Step 6: Use your browser to access your local host

Open up a browser window, and visit your local host at port 8500.

You should see this:

(http interface running on port 8500)

Good.

This means our server is running.

Once we add the “bzz:/” proxy (p.s. — there’s a url scheme with other proxies you can use, but this is the appropriate one for just retrieving/browsing web 3.0) and pass a hash or domain address, we’ll see web content!

Here’s Swarm’s landing page (hosted without a server):

(swarm landing page)

Note: you can forego having to use http with web 3.0 sites if you register the bzz url schemes with your browser.

Step 7: Surf Web 3.0!

I’m sure by now you’re itching to see what an actual dapp looks like hosted on Swarm.

Let’s see!

Swarm developers have a sample dapp located at bzz:/photoalbum.eth.

Much like viewing the Swarm homepage, if you visit this domain over the local host using the bzz scheme, you’ll be able to view and use the dapp, just as you would any other web app.

(photoalbum dapp on web 3.0)

What we’re looking at is a basic photo album with photos of planes.

With this particular dapp, the UI enables end users to post, rearrange, and delete photos; essentially giving viewers an open source photo album that they can then fork for personal use and share.

Once you make any changes to the dapp, the hash hex value (address) changes.

Why? Consider how Swarm works. Every application lives at a unique hash (a domain, basically). End users who go to the original address should be able to access the original dapp, just as you did.

If you hover over the application, you’ll notice the controls in the top left corner of the view that enable you to make changes.

(dapp delete, post, put, get controls)

So, when I move an image down one, this generates a new dapp at the following address:

(hash hex value — starting with 7, excluding that “/#1” at the end)

Think of it like a built-in version control system.

Sharing your applications with the public

It’s nice surf the TestNet web at a local port, but even better to make dapps public (maybe to share a prototype of an idea you’ve been working on).

To view dapps and resources on the regular web, you want to view that unique hash via the public gateway — swarm-gateways.net.

Steps:

  • copy the hash
  • open up a new browser window
  • preface with swarms public gateway + the bzz protocol
  • paste hash to top it off

And look, you should see the same dapp you were seeing locally:

(sample dapp via Swarm’s public gateway)

And we’re off!

That’s the Swarm TestNet in a nutshell, and the potential of this platform takes my breath away.

A couple of follow up questions you might be have:

So cool! When’s the official release be out?

Right now, from what I understand, the Ethereum team doesn’t have a set date, per se…more so a set version (version 4.0) for the official release.

How much will Swarm cost?

Zilch! It’s important to note that dapps will only be available via Swarm for 28 days, at which point you’ll have to renew/re-register them. That’s where the up-sell happens, I think.

I’ve read that Swarm will charge for hashes that want to go beyond the set freemium limit.

I can’t wait to see more tools join this ecosystem, and there’s still much to explore with Swarm after this tutorial.

For example, if you’d like to play around with contracts, gas, and ether, I have a follow up tutorial here to walk you through that process.

You should definitely check out Stack Overflow and Ethereum’s github wiki!

If you have any questions, please don’t hesitate to leave a comment or give me a shout!

Happy developing!

--

--

AnnMargaret Tutu

Research Software Engineer (ML, DL, Blockchain, Android), budding cryptologist, writer and aspiring polymath.