Skip to content
Ramesh Nair edited this page Sep 13, 2016 · 20 revisions

Running an isolated Swarm node for testing

Installation and setup

Make sure you have GOPATH variable set. For example, on my system it is set to ~/dev/go/GOPATH. Also ensure you install the latest Go version. On my system I get:

$ go version
go version go1.7 darwin/amd64

First checkout the swarm branch of the main go-ethereum repo as a subfolder of $GOPATH/src/github.com/ethereum and compile:

$ mkdir -p $GOPATH/src/github.com/ethereum
$ cd $GOPATH/src/github.com/ethereum
$ git clone https://github.com/ethereum/go-ethereum.git
$ cd go-ethereum
$ git checkout swarm 
$ godep go build -v ./cmd/geth

Set the environment variables by editing this file:

sudo vim ~/.profile

Depending on which terminal you have, you might have to do it instead on:

sudo vim ~/.shrc

An set them to the values below:

export GETH_DIR=$GOPATH/src/github.com/ethereum/go-ethereum
export GETH=$GETH_DIR/geth
export SWARM_DIR=~/bzz
export SWARM_NETWORK_ID=322
export PATH=$PATH:$GETH_DIR/swarm/cmd/swarm
  • GETH_DIR points to your git working copy (given GOPATH its standardly under $GOPATH/src/github.com/ethereum/go-ethereum)
  • GETH points to the geth executable compiled from the swarm branch. If you have systemwide install or use multiple geths you may need to change this, otherwise it is assumed you compile to the working copy of the repo.
  • SWARM_DIR is the root directory for all swarm related stuff, logs, configs, as well as geth datadirs, make sure this dir is on a device with sufficient disk space
  • SWARM_NETWORK_ID: this is by default the network id of the swarm testnet. If you run your own swarm, you need to change it, choose a number that is not likely chosen by others to avoid others joining you.

Make sure you are happy with them, otherwise change them, in which case best to put these lines in your ~/.profile.

The cluster is controlled by the swarm command in $GETH_DIR/swarm/cmd/swarm/swarm. make sure this is in your PATH (e.g., export PATH=$PATH:$GETH_DIR/swarm/cmd/swarm).

In my ~/.profile I have:

export GETH_DIR=$GOPATH/src/github.com/ethereum/go-ethereum
export GETH=$GETH_DIR/geth
export SWARM_DIR=~/bzz
export SWARM_NETWORK_ID=322
export PATH=$PATH:$GETH_DIR/swarm/cmd/swarm

Starting a node

To bootstrap a local swarm node:

swarm init 1

Putting 20 instead of 1 (i.e. swarm init 20 brings up a local cluster of 20 nodes and connect them appropriately. Note that swarm init will wipe all databases.

Error: IP address

If you see an error as follows...

Fatal: Failed to start the JavaScript console: /Users/ram/bzz/322/connect.js: invalid enode: invalid IP address
    at web3.js:3119:20
    at web3.js:6023:15
    at web3.js:4995:36
    at /Users/ram/bzz/322/connect.js:1:1

...then edit $GETH_DIR/swarm/cmd/swarm/swarm and change lines 15 to 18 to look like:

if [ "$IP_ADDR" = "" ]; then
  export IP_ADDR=`curl ipecho.net/plain 2>/dev/null`
  # export IP_ADDR=
fi

Of course I recommend you run curl ipecho.net/plain 2>/dev/null in your shell just to check that it actually returns a valid external IP address for you.

Stop and restart all nodes

swarm stop all
swarm stop 00
swarm restart all
swarm restart 00

### Attaching to a node

Once a node is running attach using swarm attach 00:

$ swarm attach 00
attaching console to instance 00
Welcome to the Geth JavaScript console!

instance: Geth/v1.5.0-unstable-4dc45770/darwin/go1.7/00
coinbase: 0x4bfcd7dce8077b5387511de0414b0711b18e160a
at block: 0 (Thu, 01 Jan 1970 08:00:00 CST)
 datadir: /Users/ram/bzz/322/data/00
 modules: admin:1.0 bzz:1.0 chequebook:1.0 debug:1.0 ens:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> 

Show node info

Example:

$ swarm info 00
swarm node information
ROOTDIR: /Users/ram/bzz
DATADIR: /Users/ram/bzz/322/data/00
LOGFILE: /Users/ram/bzz/322/log/00.log
HTTPAPI: http://localhost:32200
ETHPORT: 30300
RPCPORT: 30200
ACCOUNT: 0xae3493df5f735a26c10c6013a384de44048dc8af
CHEQUEB: 0x0000000000000000000000000000000000000000
ROOTDIR: /Users/ram/bzz
DATADIR: /Users/ram/bzz/322/data/00
LOGFILE: /Users/ram/bzz/322/log/00.log

Uploading data to Swarm

Attach a console to the Swarm instance:

$ swarm attach 00

attaching console to instance 00
Welcome to the Geth JavaScript console!

instance: Geth/v1.5.0-unstable/darwin/go1.7/00
coinbase: 0xb4b5cc2c4a19661b3d0f0b58772b391f905882d3
at block: 0 (Thu, 01 Jan 1970 08:00:00 CST)
 datadir: /Users/ram/bzz/322/data/00
 modules: admin:1.0 bzz:1.0 chequebook:1.0 debug:1.0 ens:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

Now download the ethereum-stake-voice Dapp into a folder (Note: Don't git clone as we don't want to upload the .git folder to Swarm). Let's say we've downloaded it to /opt/ethereum-stake-voice. The contents will look like:

-rwxr-xr-x@ 1 ram  staff      62  7 Jul 18:15 .gitignore
-rwxr-xr-x@ 1 ram  staff     269  7 Jul 18:15 README.md
-rwxr-xr-x@ 1 ram  staff     450  7 Jul 18:15 contract.sol
-rwxr-xr-x@ 1 ram  staff     911  7 Jul 18:15 icon.png
-rwxr-xr-x@ 1 ram  staff    1890  7 Jul 18:15 index.html
-rwxr-xr-x@ 1 ram  staff  220025  7 Jul 18:15 screenshot.png
-rwxr-xr-x@ 1 ram  staff   12051  7 Jul 18:15 scripts.js
-rwxr-xr-x@ 1 ram  staff      45  7 Jul 18:15 stake-voice.sublime-project
-rwxr-xr-x@ 1 ram  staff    2877  7 Jul 18:15 style.css

In the Swarm console type:

bzz.upload("/opt/ethereum-stake-voice", "index.html");
"263d622a546065072a2467e3f6716e95c0f82daa3c4d9f10aacb7309bafb6417"

Note the hash returned - this uniquely identifies our uploaded folder in Swarm. In the Swarm node info output above we saw HTTPAPI: http://localhost:32200. Thus open a browser and type in the following to see the app:

http://localhost:32200/bzz:/263d622a546065072a2467e3f6716e95c0f82daa3c4d9f10aacb7309bafb6417

You will probably see an styled error in the page stating that "This Browser does not support Ethereum apps.". But at least index.html and other assets (CSS, icons, etc) loaded ok.

Now launch Mist and again put in the above URL. You should see a working app like the screenshot.

File manager for Swarm data

There is an example File manager dapp for your swarm data. Once your Swarm node is up and running you can use this application to actually put data into your Swarm node.

I haven't been able to get this working yet, am awaiting help from Swarm team -> https://github.com/ethereum/swarm-dapps/issues/1

Resources