This guide sets up 2 Swarm nodes in a local private network. Each of the nodes is loaded into a specific directory; i.e. the folders ./s1
and ./s2
.
Swarm can be run without a blockchain, since each node—with the help of the bootnodes—will form a network with its peers through Kademlia.
It is through the Swarm Accounting Protocol (SWAP) that Smart Contracts come into play in Swarm, in order to form an incentivized network.
If you need these nodes to run with incentivization, please refer to the incentivized version of this guide.
websocat
(optional)websocat
is a command-line web socket client, used to query the nodes running in the private network.
If you plan to query the nodes, follow the instructions here to install it.
Start a terminal and run cd
to move to a directory where the files for the nodes will be created.
Make sure the swarm
command boots up Swarm correctly before starting the nodes.
Start the first node through:
DATADIR1="s1" &&
rm -rf "$DATADIR1" && mkdir "$DATADIR1/" &&
swarm --datadir "$DATADIR1" --ws --wsaddr=0.0.0.0 --wsapi=bzz --wsorigins='*' --bzzkeyhex 40b3e576b606d4580ad3c875e9fda07ba3e4d99a40534c5bf1bc72226451adb1 --nodekeyhex 2eae3526db799cb5f1ab6ab64255ba8182cdaeb4f773a0ae1244f4ca59978dc2
Start the second node through:
DATADIR2="s2" &&
rm -rf "$DATADIR2" && mkdir "$DATADIR2" &&
swarm --datadir "$DATADIR2" --port 40400 --bzzport 9100 --bootnodes "enode://9b7571c26d50bed78f614be5bf3b2d661176fdfeb546f100b84dd03545f4bc98e42e640286ac92fe110ec5f4995141743e47d8f642aa49ac05bd5f2cab2e881a@127.0.0.1:30399" --ws --wsaddr=0.0.0.0 --wsapi=bzz --wsport 8556 --wsorigins='*'
This will populate the directories with all of the files needed for each of the Swarm nodes.
Note that:
bootnodes
parameter.ws
(and related) parameters. The only API enabled in this case is bzz
, but others can be added at discretion (e.g. swap
, pss
, etc.). You can omit this parameter if you don’t plan to query the nodes.You can interact with the nodes in the network through the following means.
websocat
can be used to call Swarm functions exposed through RPC.
For example, to query all balances for the node listening on port 8546
, execute the following:
echo swap_balances | websocat "ws://127.0.0.1:8546" --origin localhost --jsonrpc -n --one-message &&
Note that this particular example requires SWAP to be enabled for this node.
Other calls might only be available depending on the wsapi
configuration parameter.
The Swarm documentation might not be up-to-date in terms of including all exposed functions. Search for the rpc.API
string in the Swarm codebase to figure out which calls are available.
A Swarm local web server endpoint for each node should be accessible through your browser.
The web interface will allow you to upload and download files.
By default, the server will be located at http://localhost:8500
.
You can find which port is used for each node by taking a look at the bzzport
flag used in each case.
By using the swarm
binary you can execute operations in the standard manner, such as up
, down
, etc., for the node that uses the default parameters (such as port 8500
).
You can find a list of commands here.
If you want to start from scratch, simply execute the entire code again.
If you want the to maintain state when restarting the network, only repeat the swarm
command for each node (make sure the DATADIR
variables are defined) found in the start the nodes section.
To start up more Swarm nodes, repeat the previous instructions with as many directories (./s1
, ./s2
, ./s3
, …, ./sn
) as you wish.
Make sure that:
bootnodes
parameter value.bzzkeyhex
) which are prefunded by the Ganache seed.
Guide based on Swap Test Guide by Ralph Pichler.
Go to top