Select Page

How to build Parachain on Polkadot

build defi app
Listen to the article
What is Chainlink VRF

Polkadot has designed its parachain model to support the overall advancement of web 3.0 and decentralized systems. This model employs a heterogeneous multi-chain approach that allows multiple solo chains to connect to the Polkadot’s Relay chain by obtaining a parachain slot. Here, the relay chain is the layer-zero blockchain, and parachains are the layer-1 Blockchains that run in parallel. Polkadot’s parachain model enables interoperability among multiple blockchains, allowing them to coexist and collaborate.

Developed as any layer-1 blockchains, Polkadot parachains can have their own runtime logic, own native tokens, and economies, own stipulation around implementation. In addition, by connecting to the Polkadot’s relay chain, parachains receive security from the relay chain. Also, they acquire Polkadot’s inherent benefits such as interoperability with other parachains, pooled security, scalability and governance.

It is not necessary that Parchains have to be developed as blockchains only; even applications can be deployed as parachains. DeFi (Decentralized Finance) Applications, Digital Wallets, IoT applications, Gaming apps or Web 3.0 Infrastructure, all can be deployed as parachains.

Polkadot encourages developers to deploy parachains on the Polkadot ecosystem to overcome the limitations like interoperability, scalability, and applicability that are otherwise prevalent in siloed blockchain systems. Taking the lead, this insight will explain how to set up, test, and deploy a parachain on the Polkadot network.

Before diving into that, please check this insight if you want to go through the benefits of deploying a parachain in detail.

Things to consider before building a Polkadot parachain

1.There is no go-to economic model for a parachain to follow​

Parachains exist as autonomous apps or networks with their own communities, economies, governance, rules, treasuries, and relationships with external chains. Thus, a parachain developers and its overall community are responsible for maintaining the economic policies within that parachain ecosystem.

2. There is an opportunity cost to becoming a parachain

There is a cost associated with becoming a parachain. You can gain returns on this investment by participating in the parachain selection process and earn rewards for assisting the Polkadot network in increasing its value.

3. Parachain Development Kit (PDK)

Parachain Development Kit consists of the set of tools used by developers for creating a parachain. The PDK must consist of the following key components:

State transition function(STF) helps an application to move from one state to another. The STF should be easily verifiable through witness or proof because the Relay Chain validators will validate each state received from the collator node without actually running through the entire computation.

Collator node is a peer-to-peer node in the Polkadot network. A collator node is like a network maintainer in the protocol. The node is responsible for keeping the state of the parachain available, including the new states returned from the iteration of the state transition function. A collator node must remain online to track the state and the XCMP messages routing between itself and other parachains.

Substrate and Cumulus as PDKs

Substrate and Cumulus are two existing PDKs. The Substrate is a framework for building blockchain elements such as a networking layer, consensus, and a Wasm interpreter. Substrate offers an intuitive way to build your runtime for starting a new chain. It does not, however, provide direct support for Polkadot compatibility. As a result, an additional library containing Polkadot compatibility glue code is required, which Cumulus provides.

Cumulus is a Substrate extension that makes it simple to convert any Substrate-built runtime into a Polkadot-compatible parachain. Cumulus handles a parachain’s compatibility with the Polkadot network, which is needed to implement a parachain into the Polkadot ecosystem. Cumulus manages:

  • Cross-chain message passing (XCMP)
  • An embedded full client of the Relay Chain
  • Out-of-the-box Collator node setup
  • Block authorship compatibility

Leverage Polkadot's Interoperability via custom parachains

Polkadot Blockchain Development Company

Set up your Parachain

If you want to deploy your blockchain as a parachain on Polkadot, then follow these steps:

Write the runtime logic

First, create your chain runtime logic on Substrate. This is similar to writing the runtime logic for any solo chain. You can use the Substrate parachain template.

# 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

Then, compile the runtime logic down to a Wasm executable.​ Your chain’s entire state transition function will be contained by the Wasm code blob. You will need this Wasm code blob to deploy your project to Polkadot as a parachain or a parathread.

Submit the Wasm code for validation

Polkadot validators will use the submitted Wasm code to validate the state transitions of your chain or thread.

Put Collator node into play.

Next, the validator will need to check on the most recent state transitions. For which, it will use your collator node. As the maintainer of your parachain, the collator node must perform the critical action of producing new block candidates for your chain and pass them to Polkadot validators for inclusion in the Polkadot Relay Chain.

Use Cumulus to convert your substrate-built chain logic into Polkadot-compatible parachain

As mentioned above, Substrate has its own built-in networking layer that only supports solo chains and doesn’t support chains that are connected to any relay chain. Thus, here Cumulus extension will come into play. Cumulus extension enables your substrate-built chain logic to become compatible with Polkadot, establishing your blockchain as a parachain or parathread.

Test your Parachain

Rococo Testnet​

For testing Polkadot parachains, including the externally developed one, there is a testnet called Rococo. The parachain testing on Rococo checks the passing of transfers and messages between parachains and a Relay Chain. Every message is sent to the Relay Chain, then from the Relay Chain to the desired parachain. For this testing, Rococo utilizes Cumulus and HRMP (Horizontal Relay-routed Message Passing).

Obtain ROC tokens

!drip YOUR_ROCOCO_ADDRESS​

Build and Register a Rococo Parathread​

Rococo’s parachains all use the same runtime code, but their parachain IDs for registration with the Relay Chain differ.

You will now need to run a Rococo collator. Compile the following binary to accomplish this:

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

You will now need to run a Rococo collator. Compile the following binary to accomplish this:

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

To test the parachain, you will need ROC tokens. ROC are available in the Rococo Faucet channel on Matrix. To receive ROC tokens, use the command:

Deploy your Parachain

Once your parachain is tested for successful cross-chain transfers, deploying it on the Polkadot network is next. For which you will need to acquire a parachain slot.

Substrate-based chains use an SS58 encoding for their address formats. You can check which chain corresponds to a given prefix and which prefixes are available on this page.

Acquire a parachain slot

To connect to the Polkadot network, a parachain must inhabit one of the available parachain slots. However, a parachain slot is a scarce resource on Polkadot as only limited numbers are unlocked and made available every few months. Acquiring a parachain slot is a must if a parachain wants to have guaranteed block inclusion at every Relay Chain block.

Parachain Slot distribution through Candle Auction

The parachain slots are sold using a candle auction that has been modified for blockchain security. ​

A chain candle auction is an open auction in which bidders submit higher and higher bids until the highest bidder wins the bid. In general, online candle auctions use a random number to determine the end of the auction bidding, so bidders are unaware of the duration of the opening phase.

The parachain candle auction is slightly modified because it does not use the random number to decide the duration of its opening phase. Instead, it allows bidders to have a known open phase while the close moment is determined retroactively.

During the open phase, bids will continue to be accepted. However, bids that have been made during the later part of the opening have a higher probability of losing since the retroactively determined close moment may precede the time when a bid was submitted.

Endnote

Though there are high-end benefits to becoming a parachain, such as shared security, on-chain governance, scalability, and interoperability, it is important to assess whether developing a blockchain with the goal of eventually becoming a parachain is a viable and ideal option for a project. Our Polkadot experts can help here.

If you want to build a parachain or migrate a solo chain to a parachain, please contact our Polkadot experts for consulting and development services.

Listen to the article
What is Chainlink VRF

Webinar Details

Author’s Bio

Akash Takyar
Akash Takyar
CEO LeewayHertz
Akash Takyar is the founder and CEO at LeewayHertz. The experience of building over 100+ platforms for startups and enterprises allows Akash to rapidly architect and design solutions that are scalable and beautiful.
Akash's ability to build enterprise-grade technology solutions has attracted over 30 Fortune 500 companies, including Siemens, 3M, P&G and Hershey’s. Akash is an early adopter of new technology, a passionate technology enthusiast, and an investor in AI and IoT startups.

Start a conversation by filling the form

Once you let us know your requirement, our technical expert will schedule a call and discuss your idea in detail post sign of an NDA.

All information will be kept confidential.

 

Insights