Setting up a multi node private ethereum swarm network without a blockchain
After diving through swarm’s I found the setup for multiple node swarm network confusing so I am writing this article to help those who might be looking into developing one.
What is ethereum swarm though?
Ethereum swarm is a peer to peer file storage system to allow distributed and encrypted storage of users data. Akin to how Bittorrent did or how IPFS stores files.This is being developed since data storage on the blockchain is expensive. On thing what makes swarm is different is that it will in the near future incentive users for storing others data. Akin to how Filecoin will in the near future. Though swarm’s incentive layer hasn’t been finalized yet
This definition is a very brief into swarm please read the following resources to read more about it
Installing Swarm
You can find detailed install instructions here but I will be giving you instructions related to linux as their is a small gotcha that causes trouble if you don’t notice :)
Setting up Swarm Private Network
Even though to run swarm you need to create/use an ethereum account so you can pass the accounts key to the swarm node you will be running.
We will make a new geth node and create an account within in. Then export the given key to an environment variable to be used later. Please make sure you have geth installed.
Now start the swarm node with the following command. I will explain what each flag means afterwards
- bzzaccount: Here you set the key to use that will upload into the bzzaccount.
- datadir: Directory where your swarm node will store data
- keystore: Directory where your keys will be stored. Used so swarm can use your set account password to unlock the private key of your bzzaccount.
- ens-api: By setting this to “” swarm will not connect to your block chain and run without it.
- bzzport: Your set port which you can use to upload to and download from the swarm node.
That’s all you need to run a single node but two run more than one you need to do the following.
Setting up more swarm nodes
Now if you ran the same command as before but thought that just changing the bzzport had to be changed. Well that isn’t the case. You also need to change the UDP port which isn’t mentioned in the documentation. If you don’t then you will get the following error.
Fatal: Error starting protocol stack: listen udp :30399: bind: address already in use
This was a great source of my confusion and the reason why I wrote this article.
So in order to run the second node you need to run the following commands.
Connecting Swarn Nodes
Now even though the nodes are running you need connect them together for them to communicate with each other.
To do so you can manually connect the bootnode of one swarm node to the IPC of the other. In the following we will connect the bootnode of swarnNode2 to the IPC of swarnNode.
First to find the bootnode address of swarnNode2. Run the following command.
Copy the result and add to the following command to connect the two nodes together.
Testing network connection
Now to test whether the 2 nodes are connection.You can upload a file into the first node using the following command using it’s bzzport. You will be provided back with a hash of file which acts like a url.
Now copy the hash provided and query the file using the bzzport of the second Node.
Now this should output your txt file and confirm that both of your nodes are connected. That’s it :)
Please review swarm’s documentation for further details.
Thank you for reading!