Parachains are custom, project-specific blockchains integrated within the Polkadot network.
Connected to and secured by a central Relay Chain, parachains share and benefit from its governance, interoperability, scalability, and security. Polkadot’s cross-chain architecture allows any asset or data to be exchanged between parachains, making a host of applications and new use cases possible. Parachains can also connect with external networks such as Ethereum and Bitcoin with the help of cross-network bridges. Since parachains facilitate interoperability among blockchains, and enable them to scale, they help unlock their full potential. Read on as we offer a step-by-step guide on how to build a parachain on Polkadot.
Setting up a parachain
For deploying a blockchain as a parachain on Polkadot, the following steps need to be followed:
Write the runtime logic
Write the chain runtime logic on Substrate. The process resembles writing the runtime logic for a solo chain. Use the following Substrate parachain template for convenience-
1# Clone the parachain templategit clone https://github.com/substrate-developer-hub/substrate-parachain-template
2# Switch into the parachain template directorycd substrate-parachain-template
3# Checkout the proper commitgit checkout polkadot-v0.9.16
4# Build the parachain template collatorcargo build –release
5# Check if the help page prints to ensure the node is built correctly./target/release/parachain-collator –help
Build the Wasm executable
Next, you need to compile the runtime logic to a Wasm executable. Your chain’s complete state transition function will be contained in the Wasm code blob. This Wasm code blob will be needed to deploy your parachain on Polkadot.
Validation of the Wasm code
Submit the Wasm code as Polkadot validators will use the submitted code to validate the state transitions of your parachain.
Use Collator node
The next step involves the validator checking the most recent state transitions. For this, your collator node will be used. As the collater node is responsible for maintaining your parachain, it must perform the task of creating new block candidates for your parachain and send them to Polkadot validators so they can include them in the Polkadot Relay Chain.
Convert your substrate-based chain logic into Polkadot-compatible parachain using Cumulus
Substrate has a built-in networking layer that supports only solo chains and not chains connected to any relay chain. Here comes the role of Cumulus extension which makes your substrate-based chain logic compatible with Polkadot, establishing your blockchain as a parachain.
Testing the parachain
The Rococo testnet can be used for testing Polkadot parachains. For this testing, Rococo utilizes HRMP (Horizontal Relay-routed Message Passing) and Cumulus.
Obtain ROC tokens
Build and Register a Rococo Parathread
Rococo’s parachains use the same runtime code, but the parachain IDs used for registration with the Relay Chain vary.
Now, run a Rococo collator. You can use the following binary to do this:
1cargo build –release –locked -p polkadot-collator
After the executable has been built, you can launch collators for your parachain using this code:
1./target/release/polkadot-collator –chain $CHAIN –validator
Deploying the parachain
Once your parachain has been tested for cross-chain transfers, you need to deploy it on the Polkadot network. For this, you will require a parachain slot.
Substrate-built chains use an SS58 encoding for address formats. You can check which particular prefix a chain corresponds to and which prefixes are available for use.
Get a parachain slot
A parachain must inhabit any available parachain slot in order to connect to the Polkadot network. Parachain slots, however, are a scarce resource as only a limited number of these slots are unlocked and made available every couple of months. Acquiring a parachain slot is important if a parachain wants to ensure guaranteed block inclusion.
Candle auctions: Parachain slot distribution
Parachain slots are sold in a candle auction which is a regular auction modified for blockchain security.
In a candle auction, bidders keep placing their best bids until the highest bidder wins a slot.
Starting from shared security, interoperability and scalability, the upsides to having a parachain on Polkadot are endless. Besides, Polkadot is an evolving blockchain network and is growing in demand for both startups and enterprises. In case you want a parachain developed or get an existing parachain tested, seek professional help. Sealing in a deal with Polkadot experts will prevent you from making costly mistakes.