# 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bootcamp.openguild.wtf/building-a-blockchain-with-polkadot-sdk/polkadot-sdk/cumulus/running-a-local-relaychain-network.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
