Polkadot Fundamentals and Substrate Development
Prepare A Local relay chain
Build the relay chain node
- Clone the most recent release branch of the polkadot repo -
git clone --branch release-v0.9.37 https://github.com/paritytech/polkadot.git
- Then run the following commands -
cd polkadot cargo build --release ./target/release/polkadot --help
Relay chain specs
Every Substrate-based chain requires a chain specification. The chain specification for the relay chain network provides the same types of configuration settings that the chain specification does for other networks. Many of the settings in the chain specification file are critical for network operations. For example, the chain specification identifies peers that participate in the network, keys for validators, boot node addresses, and other information.
For this tutorial, the local relay chain uses a sample chain specification file with two validator relay chain nodes—Alice and Bob—as authorities. Because a relay chain must have at least one more validator node running than the total number of connected parachain collators, you can only use the chain specification from this tutorial for a local relay chain network with a single parachain.
If you wanted to connect two parachains with a single collator each, you would need to run three or more relay chain validator nodes. In general, you would need to modify the chain specification and hard-code additional validators to set up a local test network for two or more parachains.
You can read and edit the plain text version of chain specification file. However, the chain specification file must be converted to the SCALE-encoded raw format before you can use it to start a node. For information about converting a chain specification to use the raw format, see Customize a chain specification.
The sample chain specification is only valid for a single parachain with two validator nodes. If you add other validators, add additional parachains to your relay chain, or want to use custom account keys instead of the predefined account, you'll need to create a custom chain specification file.
If you are completing this tutorial at the same time as anyone on the same local network, then you must download and modify the Plain sample relay chain spec to prevent accidentally peering with their node
Start the relay chain node
Before you can start block production for a parachains, you need to start a relay chain for them to connect to.
- Download the raw chain specification file to a working directory on the local computer.
For example, save the file as raw-local-chainspec.json in the /tmp directory. You'll need to specify the path to the file in the commands to start the nodes.
- Start the first validator using the alice account by running the following command:
./target/release/polkadot \ --alice \ --validator \ --base-path /tmp/relay/alice \ --chain /tmp/raw-local-chainspec.json \ --port 30333 \ --ws-port 9944
- You need to specify this identifier to enable other nodes to connect -
🏷 Local node identity is: 12D3KooWGjsmVmZCM1jPtVNp6hRbbkGBK3LADYNniJAKJ19NUYiq
- In a new terminal, start the 2nd validator with bob’s account -
./target/release/polkadot \ --bob \ --validator \ --base-path /tmp/relay-bob \ --chain /tmp/raw-local-chainspec.json \ --port 30334 \ --ws-port 9945