Tech Stack: How Polkadot Substrate contributes to eliminating isolation of blockchain networks.
‘Substrate takes all of our lessons learned in building Ethereum and Polkadot and distills that down into a stack of tooling that allows you to get all of those same rewards… for free’.
Dr. Gavin Wood
Why should you care about Polkadot Substrate?
Building the New Internet, aka Web 3.0, is no easy task. First off, this is due to the absence of the underlying tech stack and operational mechanisms to run the global decentralized network. The problem is now being tackled by teams building solutions that seek to enable cross-chain communication between standalone blockchains. Here we’ll touch upon the most recent one — Substrate by Parity Technologies.
First showcased by Dr. Gavin Wood at Web3 Summit to launch a custom blockchain in a matter of minutes, Substrate is basically an open-source blockchain development toolkit created to make building customized blockchains for particular applications. Generic by design, Substrate gives blockchain developers maximum technical freedom to build blockchains that they need. This workshop would serve well as the blueprint for developers seeking to start building with an adjustable blockchain framework.
Substrate 1.0 tech stack combines three new technologies — Rust, WebAssembly and Libp2p — which ultimately allows you to build a robust blockchain quickly and easily. Licensed under GPLv3, however, and sticking to the idea of maximum developer freedom, the Substrate repository is set to transition to be licensed under Apache 2.0. Substrate’s flexibility relies on the abstract consensus module API and WebAssembly-based block execution framework, which allows developers to set pretty much any parameters they want for a particular chain. More so, all Substrate chains have browser-compatible light-client functionality as well as a dynamic state-transition function allowing for seamless upgrades.
How is Substrate related to Polkadot?
Polkadot is one of the optional protocols that developers building on Substrate can connect to, yet the two technologies are inherently different. Essentially these two technologies are designed to work together, however, projects built on Substrate do not necessarily have to run on Polkadot to interoperate with other chains, i.e. Polkadot multi chain platform is one of many options to choose from when building on Substrate. Substrate’s core idea is that it’s not limited for a single network usage. Instead, it’s used for multiple chains, and potentially could be re-implemented in other languages.
There is a developer hub where you can get an overview of the system and learn how to create a custom Substrate chain. As the developer hub is a work in progress, there is also Substrate Technical chat open for all sorts of inquires.
The Substrate stack is composed of three key components:
- Substrate Core
Substrate Core is the minimal base for building blockchains that gives you a basic foundation instead of building a blockchain from scratch. Here are the features you get by default:
- Block synchronisation
- Extensible JSON-RPC API endpoints
- Crypto primitives library
- Pervasive and secure networking via libp2p
- Light client
- Chain specification and versioning
- Pluggable consensus
- Transaction queue and block production mechanism
- Sandboxed WebAssembly interpreter
- Interchain connectivity via the Polkadot protocol.
What you get with Substrate Core
- Substrate Runtime Module Library (SRML)
Substrate architecture separates the basic functionality of a network blockchain node and the chain-specific implementations by executing the latter in a separate WebAssembly environment. You have absolute freedom to write the chain logic in any language that can compile down to WebAssembly (Rust, C/C++, C#, Go, etc). You can add modules from the Substrate Runtime Module Library, or SRML. With SRML, you can take off-the-shelf components, plug them together, and build a blockchain that does what you want it to do. Substrate modules include:
- Accounts & Balances — basic cryptocurrency, including account management and viewing
- Assets — simple, secure additional on-chain fungible assets
- Consensus — setting and modifying runtime code and storage (i.e. the set of authorities as a list of session keys on-chain), and reporting offline or misbehaving validators
- Contracts — turbo-charged Wasm-based smart contracts
- Council — council election and proposals
- Democracy — public proposals and referendums
- Sessions — key rotation for authorities
- Staking — Proof-of-Stake logic, including both staking and nominating of validator accounts
- Timestamp — have your chain know about time
- Treasury — decentralised grants, similar to a DAO
For example, if you want to create a Proof-of-Stake smart contract blockchain, you would take Substrate Core and plug in the Accounts & Balances, Staking, and Contracts modules. Once Polkadot launches, you could also make it interoperable by plugging it into Polkadot.
- Substrate Node.
Substrate Node allows you to deploy a blockchain with maximum ease providing the foundation needed to build a blockchain. Core parts include, but are not limited to, a light client, storage, and a crypto primitives library. Further, developers can plug in their own consensus mechanisms and connect to other chains via Polkadot. Aura/GRANDPA consensus is included in the box, but there will be more consensus mechanisms to choose from The SRML offers a suite of modules builders can choose from to implement into their chains. For example, the Accounts & Balances module enables cryptocurrency functionality, whereas the Staking module equips a chain with proof-of-stake logic. In addition to these modules, developers can write chain logic in any WebAssembly-compatible programming language, such as Rust (which is what Parity Ethereum uses), Go, or C. Substrate Node, the final key component, is simply used to deploy the blockchain.
In addition, there is a Peripheral support infrastructure specifically designed to provide additional functionality to Substrate and Polkadot that includes:
- Polkadot Telemetry Service — network information including what nodes are running the chain, what software versions they are running, and sync status.
- Jaco’s UI for Substrate and Polkadot — built with React.js and RxJS. API docs and examples available.
- Substrate UI — built with the Bonds oo7 library. API Docs available.
- Polkadash — validator monitor.
- Polkabot — network monitoring and reporting.
- Polkascan — blockchain data explorer and analytics.
Why should a blockchain developer care about Substrate?
As Dr. Gavin Wood puts it, “by pushing out Substrate, we can create a whole new class of sort of development teams and development applications that sit right in the sweet spot between the two where you don’t have to know everything, you don’t have to do everything to develop your whole new blockchain, but you can do just enough that you do have a domain-specific chain, that has its own parameterization, and its own features that allow you to get a particular job done, and done well, that wouldn’t have been possible before because smart contracts are too bloaty, and writing your own chain is too much work.”
Indeed, these core Substrate’s features in the longer run have the potential to meet all sorts of developers’ needs:
- Max technical freedom and ease
Substrate is architected to be as generic as possible in order to give a developer maximum technical freedom when designing a blockchain. It has a 100% abstract execute block function encoded in WebAssembly that can be targeted from any one of a number of languages, including C++ and Rust. The execute block function is hot-swappable, meaning you can upgrade your chain’s logic without a hard fork.
- Generalized block format and consensus mechanisms
Consensus mechanism is also generalised. The API provided lets you roll your own consensus mechanism if you want, and it can handle most consensus algorithms out there. Substrate 1.0 Beta provides a combined Aura/GRANDPA consensus, with more consensus algorithms to be provided in subsequent releases. Down the road, consensus will be hot-swappable, meaning you can start your blockchain with one consensus mechanism and switch to another down the line without a hard fork. More so, thanks to our exquisite API, you can roll out your own customized consensus mechanism, if needed. We’ve also included GRANDPA, our new consensus algorithm that’s going to power Polkadot, and we’re planning on adding Ouroboros and Proof-of-Work.
A block format is generalized and extensible as well, provided that your block format encodes the two or three specific values, and a parent hash.
- Agnostic to the underlying crypto databases
A developer can choose between the default Ethereum-like Merkle Patricia Tree, or any of the other existing crypto databases, or introduce your own, or have hierarchical trees — that’s entirely up to your project needs.
- Fully configurable
Substrate allows you to easily configure your blockchain, but also take complete control over the code should you need to. This flexibility between ease and technical freedom is achieved through a modular design: Substrate is separated into Substrate Core and Substrate Runtime Module Library (SRML) and comes with a pre-assembled Substrate Node that is simple to configure.
- Secure and interoperable
To sum up Substrate advantages, you can basically launch your chain and then further down the road change its functions without any hard forks. Substrate can simplify the development of your next blockchain big time. We will be following Parity Tech team’s further advances, meanwhile tech heads can follow Substrate Developer Hub, and reach out to Substrate’s Support Team.
Has anyone tried building on Substrate yet? Drop a comment!