3. Getting started¶
The first thing to do is to start up your Swarm node and connect it to the Swarm network.
3.1. Running Swarm¶
To start a basic Swarm node you must have both
swarm installed on your machine. You can find the relevant instructions in the Installation and Updates section.
geth is the go-ethereum client, you can read up on it in the Ethereum Homestead documentation.
To start Swarm you need an Ethereum account. You can create a new account in
geth by running the following command:
$ geth account new
You will be prompted for a password:
Your new account is locked with a password. Please give a password. Do not forget this password. Passphrase: Repeat passphrase:
Once you have specified the password, the output will be the Ethereum address representing that account. For example:
Using this account, connect to Swarm with
$ swarm --bzzaccount <your-account-here> # in our example $ swarm --bzzaccount 2f1cd699b0bf461dcfbf0098ad8f5587b038f0f1
(You should replace
2f1cd699b0bf461dcfbf0098ad8f5587b038f0f1 with your account address key).
Remember your password. There is no forgot my password option for
3.2. Interacting with Swarm¶
$BZZKEY$ refers to your account address key.
Swarm is fully compatible with Geth Console commands. For example, you can list your peers using
admin.peers, add a peer using
admin.addPeer, and so on.
You can use Swarm with CLI flags and environment variables. See a full list in the Configuration .
3.3. How do I enable ENS name resolution?¶
The Ethereum Name Service (ENS) is the Ethereum equivalent of DNS in the classic web. It is based on a suite of smart contracts running on the Ethereum mainnet.
In order to use ENS to resolve names to swarm content hashes,
swarm has to connect to a
geth instance that is connected to the Ethereum mainnet. This is done using the
First you must start your geth node and establish connection with Ethereum main network with the following command:
for a full geth node, or
$ geth --syncmode=light
for light client mode.
Syncing might take a while. When you use the light mode, you don’t have to sync the node before it can be used to answer ENS queries. However, please note that light mode is still an experimental feature.
After the connection is established, open another terminal window and connect to Swarm:
Verify that this was successful by pointing your browser to http://localhost:8500/bzz:/theswarm.eth/
3.3.1. Using Swarm together with the testnet ENS¶
It is also possible to use the Ropsten ENS test registrar for name resolution instead of the Ethereum main .eth ENS on mainnet.
Run a geth node connected to the Ropsten testnet
$ geth --testnet
Then launch the
swarm; connecting it to the geth node (
Swarm will automatically use the ENS deployed on Ropsten.
For other ethereum blockchains and other deployments of the ENS contracts, you can specify the contract addresses manually. For example the following command:
$ swarm --ens-api eth:<contract 1>@/home/user/.ethereum/geth.ipc \ --ens-api test:<contract 2>@ws:<address 1> \ --ens-api <contract 3>@ws:<address 2>
Will use the
geth.ipc to resolve
.eth names using the contract at address
<contract 1> and it will use
ws:<address 1> to resolve
.test names using the contract at address
<contract 2>. For all other names it will use the ENS contract at address
<contract 3> on
3.3.2. Using an external ENS source¶
Take care when using external sources of information. By doing so you are trusting someone else to be truthful. Using an external ENS source may make you vulnerable to man-in-the-middle attacks. It is only recommended for test and development environments.
Maintaining a fully synced Ethereum node comes with certain hardware and bandwidth constraints, and can be tricky to achieve. Also, light client mode, where syncing is not necessary, is still experimental.
An alternative solution for development purposes is to connect to an external node that you trust, and that offers the necessary functionality through HTTP.
If the external node is running on IP 126.96.36.199 port 8545, the command would be:
$ swarm --ens-api http://188.8.131.52:8545
You can also use
https. But keep in mind that Swarm does not validate the certificate.
3.4. Alternative modes¶
Below are examples on ways to run
3.4.1. Swarm in singleton mode (no peers)¶
If you don’t want your swarm node to connect to any existing networks, you can provide it with a custom network identifier using
--bzznetworkid with a random large number.
3.4.2. Adding enodes manually¶
By default, Swarm will automatically seek out peers in the network.
Additionally you can manually start off the connection process by adding one or more peers using the
admin.addPeer console command.
(You can also do this in the Geth Console, as seen in Section 3.2.)
When you stop a node, all peer connections will be saved. When you start again, the node will try to reconnect to those peers automatically.
Where ENODE is the enode record of a swarm node. Such a record looks like the following:
The enode of your swarm node can be accessed using
geth connected to
geth is used for two different purposes here: You use it to run an Ethereum Mainnet node for ENS lookups. But you also use it to “attach” to the Swarm node to send commands to it.
3.4.3. Connecting to the public Swarm cluster¶
By default Swarm connects to the public Swarm testnet operated by the Ethereum Foundation and other contributors.
The nodes the team maintains function as a free-to-use public access gateway to Swarm, so that users can experiment with Swarm without the need to run a local node. To download data through the gateway use the
3.4.4. Metrics reporting¶
Swarm uses the go-metrics library for metrics collection. You can set your node to collect metrics and push them to an influxdb database (called metrics by default) with the default settings. Tracing is also supported. An example of a default configuration is given below:
$ swarm --bzzaccount <bzzkey> \ --debug \ --metrics \ --metrics.influxdb.export \ --metrics.influxdb.endpoint "http://localhost:8086" \ --metrics.influxdb.username "user" \ --metrics.influxdb.password "pass" \ --metrics.influxdb.database "metrics" \ --metrics.influxdb.host.tag "localhost" \ --verbosity 4 \ --tracing \ --tracing.endpoint=jaeger:6831 \ --tracing.svc myswarm