Rise In Logo





Polkadot Fundamentals and Substrate Development

Simulating a complete substrate network

In the previous section we started a single substrate node. But in reality, nodes don’t operate in isolation and they are usually part of a network.

In this section, let’s simulate a substrate network by adding multiple nodes to the network and see how they interact.

Starting the node

Start a terminal, change directory into the project and run the command below to purge old chain data - 

./target/release/node-template purge-chain --base-path /tmp/alice --chain local

The command will prompt you to confirm the operation, press ‘Y’.

Start the local blockchain node using the “alice” account by running the following command - 

./target/release/node-template
--base-path /tmp/alice
--chain local
--alice
--port 30333
--ws-port 9945
--rpc-port 9933
--node-key 0000000000000000000000000000000000000000000000000000000000000001
--telemetry-url "wss://telemetry.polkadot.io/submit/ 0"
--validator

This will start up the node and you should observe the terminal to see if all is going well and there are no errors.

Adding another node

With the commands we ran in the previous section, one substrate node is running in a terminal and now we want to add another node in the network. To do this, we will open up a new terminal to start and interact with the second node and purge old chain data with the following command - 

./target/release/node-template purge-chain --base-path /tmp/bob --chain local -y

You will notice the presence of a “-y” flag - this flag enables you to remove old chain data without prompting you to confirm the operation.

Now we will start the new node but using “bob” account (just like we used “alice” account last time).

Run this command - 

./target/release/node-template
--base-path /tmp/bob
--chain local
--bob
--port 30334
--ws-port 9946
--rpc-port 9934
--telemetry-url "wss://telemetry.polkadot.io/submit/ 0"
--validator
--bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp

Verify Block production

Now that both the nodes are running, all you need to do is observe whether both the terminals are showing the same messages, you will see similar lines in the terminals.

You will see that node identity was discovered and the node has 1 peer where peer is the other node that we have started.

The nodes will also be producing blocks and finalizing blocks and you will see messages to indicate the same.

You can then shut down one of the nodes by pressing control+c and you will see that the first node will have 0 peers remaining.

Project

Rise In Logo

Rise together in web3