> For the complete documentation index, see [llms.txt](https://bootcamp.openguild.wtf/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bootcamp.openguild.wtf/building-a-blockchain-with-polkadot-sdk/polkadot-sdk/cumulus/running-a-local-relaychain-network.md).

# Running a local relaychain network

Below materials are primarily referenced from: <https://hackmd.io/@s_iGZLIITG6WjSgnFX0pcg/the-collator-setup-guide>

Before setting up a local relaychain network, walk through these materials:&#x20;

* [Understanding the sharded network design of Polkadot](/building-a-blockchain-with-polkadot-sdk/polkadot/additional-reads/understanding-the-sharded-network-design-of-polkadot.md)
* Prepare a local relaychain: <https://docs.substrate.io/tutorials/build-a-parachain/prepare-a-local-relay-chain/>
* Connect a local parachain: <https://docs.substrate.io/tutorials/build-a-parachain/connect-a-local-parachain/>

## Getting Started

Make sure they are compiled based on the same release version. If you want to connect the parachain to an already running Relay chain you can skip the Polkadot steps.

NOTE: Our polkadot version for the binaries is `v1.14.0`

* Build Polkadot:

```sh
git clone https://github.com/paritytech/polkadot
cd polkadot
cargo build --release
```

* Build Parachain:

```sh
git clone https://github.com/paritytech/polkadot-sdk-parachain-template
cd polkadot-sdk-parachain-template
cargo build --release
```

## Generate chainspec, runtime wasm, genesis state <a href="#generate-chainspec-runtime-wasm-genesis-state" id="generate-chainspec-runtime-wasm-genesis-state"></a>

### Chainspec <a href="#chainspec" id="chainspec"></a>

* Plain:

```sh
./target/release/parachain-template-node build-spec --disable-default-bootnode > parachain-chainspec.json
```

**Important**: edit the `parachain-chainspec.json` where necessary. For example; set the correct `para-id`, `protocolid` or `relay_chain`.

The `para-id` needs to be reserved on the Relay Chain. Check out the ["Connect a local Parachain"](https://docs.substrate.io/tutorials/build-a-parachain/connect-a-local-parachain/) tutorial and look for the step *"Reserve a unique identifier"*

* Raw:

```sh
./target/release/parachain-template-node build-spec --chain parachain-chainspec.json --disable-default-bootnode --raw > parachain-chainspec-raw.json
```

### Runtime wasm <a href="#runtime-wasm" id="runtime-wasm"></a>

Required to register the Parachain on the Relay Chain. The Relay Chain needs the runtime code to validate blocks.

```sh
./target/release/parachain-template-node export-genesis-wasm --chain parachain-chainspec-raw.json parachain-wasm
```

### Genesis state <a href="#genesis-state" id="genesis-state"></a>

Required to register the Parachain on the Relay Chain. Both the Relay Chain and the Parachain need to start from the same starting state.

```sh
./target/release/parachain-template-node export-genesis-state --chain parachain-chainspec-raw.json parachain-genesis-state
```
