DARWINIA NETWORK
Published in

DARWINIA NETWORK

「Understanding Darwinia 1–8」How to Develop a Substrate-to-Substrate Bridge

Summary

This article describes how to develop a Substrate-to-Substrate bridge for Darwinia Bridger based on parity-bridges-common. A tutorial on how to a generic Substrate-to-Substrate bridge can be found in the above repository.

Integration

If you want to add a new Substrate-to-Substrate to the project Darwinia Bridger, you can refer to The Design & Development of the New Version of Bridger to familiarize yourself with the development of a new bridge instance in the Bridger project.

Apart from that, you can also create an independent project to implement a new bridge. Utility libraries provided by Darwinia Bridger can make your development more smoothly.

Steps

Create a project

You can start with creating a new project based on the bridge template.

Implementation of dependency libraries

To build a new Substrate-to-Substrate bridge based on parity-bridges-common, we need to implement some dependency libraries first. The traits listed below to implement are all from parity-bridges-common.

In addition to those traits, two types need to be defined.

This part defines a set of data types used by the current blockchain, and common calls for submitting transactions(e.g. sign_transaction ), and thus paves the way for later development. You can customize these types when implementing these traits to suit your network.

Preparation of Code for Relay

After the defining the on-chain data types and calls for submitting transactions, you can write the code for headers/messages relay.

Note: A bridge needs two components, headers relay and messages relay, to work properly.

The following methods are of great importance.

headers

  • make_submit_finality_proof_transaction

All the Substrate-to-Substrate bridge headers are relayed to the current network by calling this method.

messages

  • types

There are many definitions of types in the messages section. The bridge queries the OutboundLane channel on the source for transactions waiting to be relayed to the InboundLane on the target chain, and the stored keys are constants for such queries.

  • make_messages_receiving_proof_transaction

Once the message is dispatched by the target chain, the bridger will submit a transaction of confirmation to the source chain. This method is for the construction of such a confirmation transaction.

  • make_messages_delivery_transaction

When the relayer finds messages to deliver in the OutboundLane on the source chain, it uses this method to make(generate) a transaction on the target chain and submit it.

  • runner

A runner must be defined to actually launch the bridger.

Start the Bridge

Now you can start the bridge to call the runner. Some points are worth noting in this part of code.

First comes the data preparation. After the user runs the command start, it will launch the bridge service, read the data from the configuration file, and convert it into the format required by runner.

Then two instances of OnDemandHeadersRelay(source) are launched, corresponding to the source chain and the target chain respectively. These two subroutines serve the following messages-relay tasks on demand.

Finally, one messages-relay (source) **will be launched for each preset lane. Since parity-bridges-common adopts the strategy of on-demand relay, it notifies the OnDemandHeadersRelay objects to relay the header corresponding to the current message.

Discussion

This article only covers how to develop a Substrate-to-Substrate bridge from a developer’s perspective using parity-bridges-common, and leaves out the full workflow of parity-bridges-common, which is complex and involves many modules and concepts.

Those who are interested can refer to the following resources that describe the implementation of the Substrate to Substrate bridge.

Contact Us

Crab Network is holding an online hackathon on the DoraHacks platform to fund the development of projects and applications that contribute to the Crab ecosystem and promote overall network growth. The USD 107,000 in the prize pool, will be allocated based on the votes of the judging panel.

Get involved now:

🔥Developer Documentation: https://docs.crab.network/builders/get-started/darwinia-dev

🔥Developer Telegraph Group: https://t.me/DarwiniaDev

🔥Darwinia DApps Builders: https://t.me/+fJiD_IwvwjhjYmQ9

🔥Crab-Grants Guide Workshop: https://www.youtube.com/watch?v=zlmBa1bzABw

Blockchain Explorer: https://crab.subscan.io/

GitHub: https://github.com/darwinia-network

Official Website: https://crab.network/

Official Twitter: https://twitter.com/DarwiniaNetwork

Official Telegram: https://t.me/DarwiniaNetwork

Official Medium: https://darwinianetwork.medium.com/

About Darwinia Network

Darwinia Network is a decentralized cross-chain bridge network building on Substrate, which is the “Web 3.0 cross-chain bridge hub” of the cross-chain ecology. It provides a safe and general bridging solution, connects to Polkadot, Ethereum, TRON and other heterogeneous chains by cross-chain transfer of assets and remote chain calls. The application areas of Darwinia Network include DeFi, cross-chain NFT trading, games, etc.

Darwinia Network has gained a high reputation and recognition along the way to build the decentralized cross-chain bridge protocol. In 2020, Darwinia was written in Polkadot light-paper as one of the friends of Polkadot and Substrate. And Darwinia was selected to join Substrate Builder Program and Web3.0 Bootcamp, and for the outstanding work in Substrate Builder Program, Darwinia Network was officially awarded the Level 2 badge by Parity. The products and tools developed by Darwinia have been rewarded three W3F Grants.

About Crab Network

Crab is a canary network with real economic value for Darwinia, and its positioning is similar to Polkadot’s Kusama Network. Crab Network has won the 22nd Kusama parachain slot! You can check Crab status through Polkadot{.js} , Subscan or Subview.

Crab provides smart contract solutions based on DVM (Darwinia Virtual Machine), which is compatible with the EVM (Ethereum Virtual Machine) paradigm at a low level. Therefore, it is easy for projects in the Ethereum ecosystem to migrate to the Crab Smart Chain. (Tips: DVM is built on Frontier with a fully EVM-compatible instruction set and an Ethereum RPC-like external interface.)

Follow Us: [Github] [Website] [Medium] [Telegram] [Twitter]

--

--

--

Darwinia Network provides a light-client based, programmable, universal cross-chain message Network for DApp developers.

Recommended from Medium

BOGChartsV3 is here!

CS371p Spring 2022: Malithy Wimalasooriya — Week 4

How to Sync AWS S3 Bucket on Git Push using GitHub Actions

Siri, let there be light.

The Evolution of Programming

Programmatic Views in Swift: Parallax and Scale

Automate Your Scripts With Expect

Night photo of blurred headlights and taillights on a highway

Configuring Docker using Ansible

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
Darwinia

Darwinia

As an open cross-chain bridge protocol based on Substrate, Darwinia focuses on the construction of future Internet of Tokens. TG: http://t.me/DarwiniaNetwork

More from Medium

1BTC Rewards for Darwinia Polkadot Parachain Slot Auction have been Delivered!

Monthly Report | Statemine and Bifrost cross-chain channel opened to expand asset usage scenarios

Accounts in SORA

Discussion Amendment Proposal YIP-004 (New uBTC Token and youves Flat-Curve DEX)