Nerd For Tech
Published in

Nerd For Tech

How to build Parachain on Polkadot?

Polkadot is an interoperability project that has been developed to unite all the blockchains. Polkadot’s unique multichain structure allows both private and public blockchains to communicate with one another. So, Polkadot may be considered a revolutionary innovation because it acts as that connecting link between different blockchains. With parachains, the Polkadot network is able to parallelize transaction processing which helps it carve a niche for itself as an interconnected blockchain network.

So, what are parachains?

Polkadot parachain can be a private, public or hybrid blockchain. It can also be a protocol for dApp development. In fact, a parachain does not necessarily have to be a blockchain, even a dApp can be developed as a parachain. So, parachains are project-specific, customized blockchains or dApps integrated within the Polkadot network. Each parachain acquires inherent interoperability with other parachains connected to the Polkadot relay chain. The relay chain provides shared security, cross-chain interoperability and consensus to the the parachains. Parachains, together with polkdaot relay chain function as an interoperable and harmonized ecosystem of blockchains.

How does Polkadot’s architecture work?

There are two layers at which the Polkadot network operates-Layer 0 and Layer 1. While Layer 1 comprises the parachains, Layer 0 entails the main relay chain parallel to which all the parachains run. Collators are special nodes that connect a parachain to the relay chain. They act as full nodes of the parachain and carry vital information linked to it.

Parachains can have their own native tokens, and stipulation around implementation. In addition, they define the process of incentivization for the collator nodes. Parachains share Polkadot’s interoperability and composability, which enables them to communicate with other parachains, which prevents the main relay chain from becoming clogged with every transaction that passes through it. The relay chain manages staking transactions and governance besides sharing security with the entire network. A unique attribute of Pokadot’s approach is that parachains can be purchased by other crypto projects. And to secure one of these rare parachain slots, projects must win an auction. These auctions are generally held once parachains are ready to be tested and deployed. The DOT token is the bidding currency in these auctions. After a project acquires a parachain, they can customize it as per their requirements.

Setting up a Parachain

Deploying your blockchain as a parachain on Polkadot will require you to follow the under-mentioned steps-

Write the runtime logic

Use Polkadot’s Substrate for creating the chain runtime logic. The process will be similar to creating any other solo chain’s runtime logic. When you create the logic, consider using the following Substrate parachain template.

1# Clone the parachain templategit clone https://github.com/substrate-developer-hub/substrate-parachain-template# Switch into the parachain template directorycd substrate-parachain-template# Checkout the proper commitgit checkout polkadot-v0.9.16# Build the parachain template collatorcargo build --release# Check if the help page prints to ensure the node is built correctly./target/release/parachain-collator --help

Build the Wasm executable

the next step would involve compiling the runtime logic to a Wasm executable. The Wasm code blob will contain the chain’s complete state transition function. For deploying your parachain or parathread to Polkadot, you will need this Wasm code blob.

Get the Wasm code validated

The state transitions of your parachain or parathread will be validated by Polkadot validators by examining your submitted Wasm code.

Put Collator node into play

The validator will then check on the latest state transitions, and they will use your collator node for this. Your collator node is your parachain’s maintainer. So, it must produce new block candidates for your chain and send them to Polkadot validators, so they can include them in the Polkadot Relay Chain.

Using Cumulus for converting your chain logic to a parachain

Substrate’s built-in networking layer supports only solo chains. It doesn’t support any chain connected to relay chains. Cumulus extension can be of help here. Cumulus extension allows your substrate-built chain logic to be compatible with Polkadot, by turning your blockchain into a parathread or parachain.

Testing the Parachain

Rococo Testnet​

The testnet Rococo can be used to test Polkadot parachains, even the externally developed ones. Rococo’s parachain testing ensures that transfers and messages between parachains and a Relay Chain don’t get passed unchecked. Messages first reach the Relay Chain from where they are sent to the parachains. Rococo uses Cumulus and HRMP for this testing.

Get ROC tokens

To test the parachain, you will need ROC tokens. ROC tokens are available on Matrix in the Rococo Faucet Channel. You can use the undermentioned command to get ROC tokens.

1!drip YOUR_ROCOCO_ADDRESS​

Register and Build a Rococo Parathread

When registering with the Relay Chain, rococo parachains share the same runtime code but use different parachain IDs.

To run a Rococo collator, you will need to compile the following binary:

1cargo build --release --locked -p polkadot-collator

After the executable has been built, it’s time to launch collators for your parachain:

1./target/release/polkadot-collator --chain $CHAIN --validator

Deploying the Parachain

Once your parachain passes cross-chain tests, it is ready to be deployed on the Polkadot system. To do so, you’ll need to obtain a parachain slot.

Substrate-based chains use an SS58 encoding in their address formats. Check which chain corresponds to a particular prefix, and which prefixes are currently available.

Obtain a parachain slot

For parachains to connect to Polkadot’s network, they need to occupy any available slot. Parachain slots are a limited resource on Polkadot, and they are only unlocked in small numbers and become available every few months. A parachain must have a parachain slot to ensure its inclusion in the Relay Chain.

Distribution of parachain slots via candle auction

Parachain slots are sold through a modified candle auction for blockchain security.

A candle auction is an online auction where bidders make their best bids, until the highest bidder wins. A random number is usually used by online candle auctions to mark the end of the auction, so, bidders do not know the duration of the opening phase. Parachain candle auction is modified in that it doesn’t use a random number to determine its duration. It gives bidders a predetermined opening phase, and the closing period is determined retroactively.

It’s important to note that bids made in the latter part of the opening phase are likely to be rejected since the retroactively determined closing moment could have occurred before the bid was submitted.

Endnote

Starting from interoperability to scalability and shared security, the benefits of having a parachain are endless. Also, Polkadot is a rapidly evolving blockchain protocol, and both startups and enterprises are using it as a foundation for blockchain development. So, if you want a parachain project developed or get your parachain tested, then seeking professional help would be the best bet. However, seal in your deal only with Polkadot experts.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
LeewayHertz

LeewayHertz

Full-stack software development company for startups and enterprises using blockchain, AI, IoT, AR and cloud computing. https://www.leewayhertz.com