As of 2021, Bitcoin and cryptocurrencies more broadly have become well-known phenomenons throughout the world. Furthermore, the use of such virtual currencies is growing rapidly as people become increasingly interested in cryptocurrency and blockchain. Along with this heightened interest in crypto, the amount of investments is growing at a similar pace. Blockchain is the technology underpinning cryptocurrencies and which makes them possible. As awareness and adoption of crypto grows, cross-industrial demand for blockchain follows. However, even though most people have heard of blockchain, most of them are unaware of how it actually works and how to build one. Creating a fully functioning blockchain can be challenging and time-demanding. One of the initiatives trying to solve this is Parity Technologies’ Substrate.
In short, Substrate is a framework of modules that enables developers to create purpose-built blockchains, by combining pre-built or custom modules. You may perhaps already know Substrate as the backbone of the Polkadot ecosystem. Substrate provides the user with several necessary components for creating a distributed blockchain network. Some of these components are a database, network layering, consensus engines, and transaction queues. However, before trying to understand Substrate, we must establish and understand what blockchain technology is.
If you appreciate easily understood breakdowns of various facets of blockchain technology like this, you should then join over 30,000 others and enroll in Ivan on Tech Academy. Ivan on Tech Academy offers dozens of blockchain and cryptocurrency courses, covering everything from crypto basics to smart contract coding, DeFi, Ethereum game programming and much, much more. What are you waiting for?
What is a Blockchain?
So, to fully understand the premise of Parity Substrate, we must first make sure we understand blockchains. In its purest form, a blockchain is a sequence of blocks consisting of data that form a chain. Blockchains can vary in detail depending on the functionality that the chain has. However, in a higher sense, practically all blockchains share some characteristics.
As the name suggests, a blockchain consists of blocks that essentially form a chain, or “blockchain”. These blocks all contain data, and this data can generate a unique identifier that is attached to this block. Furthermore, one part of the data in the block is the unique identifier of the parent block. The parent block can be understood as a preceding block in this chain of blocks.
If any changes occur within a block, the unique identifier changes with it. Since the block subsequent to the modified block contains this identifier, any new blocks following this will change as well. This will have a literal chain reaction throughout the whole system, changing all blocks in the chain following a modified block. Consequently, this system makes it easy to check if any block in the chain has changed since all that is needed is to look at the last block.
Due to the blocks’ immutable and transparent properties, it makes blockchain perfect for keeping track of a distributed ledger. The data in the ledger changes with every new block added and contains instructions on how the state of the ledger should convert from each block.
However, there are actually rules on how the ledger can change, and a state transition function defines these rules. For some cryptocurrencies, these rules can be very basic such as: ”Users can only spend funds they own”.
Whenever a collection of transactions is accumulated, they form a new block that is added to the end of the chain. This process allows for the state of the blockchain to change over a time period.
Finalizing the Blocks
Once a block is created containing several transactions, it can be shared with others when constructing the same ledger. Since these chains are of a decentralized nature, it is possible to have two different blocks competing for the same position in the chain. Here is where block finalization mechanisms come into play, to determine which chain of blocks is the canonical blockchain. For all blockchains, only one true final state of the ledger should exist. The name of any other chains that split off from this true form of the ledger are known as “forks”.
However, forks are quite normal and expected in any blockchain, and are an intended mechanism rather than a problem. The finalization process helps the forks in the chain get back in sync.
It might already be obvious to you that the structure of blockchains are decentralized and that they are distributed in nature. Therefore, they rely on numerous users from all over the world to keep track of the ledger and making sure that everything is functioning correctly. Moreover, these ledger participants can run what is known as a node. A node is basically a computer program that sticks to the rules of the chain network and connects with the other nodes.
Furthermore, blockchain networks are often open to everyone meaning that everyone can participate in this process. However, since they are open to everyone, this also means that malicious actors can join the network. But there are mechanisms in most blockchains that incentivize good behavior and punishes bad behavior. This means that the chains can function without a central authority.
The Substrate Framework – What is Substrate?
Now that we have established what a blockchain is and better understand how they work, we can move on to this article’s central part. As mentioned in the introduction, Substrate is a modular framework.
This means that the framework allows the users of Substrate to add prebuilt components to create and modify a blockchain in a short amount of time. Moreover, Substrate was announced back in 2018 by data scientist and Ethereum co-founder Gavin Wood, at the Web3 Summit in Berlin. The Oxford Dictionary defines a substrate as “a substance or layer that underlies something, on which processes occur”. As such, it’s clear to see that Substrate’s vision is to underpin blockchains, or that blockchains will be created using Substrate, and “on which processes will occur”.
Various different blockchains already run Substrate, such as Polkadot and the Kusama “canary chain”. In essence, Parity Substrate seeks to provide quick and easy blockchain development. A critical point about the Substrate framework is that it is extensible. This basically means that the Substrates will make a few assumptions about your blockchain designs with the purpose of being as generic as possible.
Even though the Substrate framework has the purpose of making blockchain development easier and more accessible to everyone, there are still requirements needed to benefit from Substrate’s full potential. The developers of Substrate suggest that a good knowledge of basic blockchain concepts as well as computer science are good skills to have before taking a shot at Substrate.
Along with this, Substrate is built using the Rust programming language. It is, therefore, beneficial, but not necessary, to have some basic skills of Rust for those looking to work with the Substrate framework. Additionally, Substrate features tight integration with the WebAssembly (Wasm) runtime.
Architecture – The Substrate Client
The Substrate framework runs on a Substrate-based blockchain node through the Substrate application. This node consists of several different modules such as storage, runtime, and a peer-to-peer network. We will now go through six components that are part of the framework.
- Storage: As we established earlier regarding blockchains, they represent a decentralized system. Storage, in this case, is used to maintain the constantly evolving state of this decentralized system or the blockchain.
- Runtime: Runtime is another important mechanism or component on the Substrate node. Runtime logic defines how blocks are processed where we, for example, can find the state transition logic. In the framework, runtime code is accumulated to Wasm (WebAssembly) and is part of the blockchain’s storage state.
Due to this function, it is possible to utilize one of the main features of a Substrate product blockchain which is forkless runtime upgrades. This is a neat function that comes into play when updating the runtime logic of a chain. Traditionally, when updating the state transition function of a chain, it requires a hard fork. However, these forkless runtime upgrades allow the runtime logic to update in real-time without the necessity to cause a fork in the chain.
- Peer-to-Peer (P2P) network: The capabilities of Substrate allow the client to communicate with other participants in the network.
- Consensus engines: One of the modules of the framework is consensus engines. These engines provide logic that allows the network users to agree on the state of the blockchain. With the framework, it is possible to supply or create a custom consensus engine and also ships with different consensus mechanisms. These mechanisms have been developed and built on Web3 foundation research.
- RPC: RPC stands for remote procedure call, and it allows the users of the chain to interact with the network. It also means that the framework provides WebSocket and HTTP RPC servers.
- Telemetry: The last component is telemetry metrics that are revealed through the use of an embedded Prometheus server.
Substrate users can utilize the framework in three different ways: with Substrate Node, Substrate FRAME, and Substrate Core. They all fill different functions of Substrate, and we will go through each of the options for the users.
The JSON file allows the user to customize the genesis state of the modules in which the runtime of the Node consists. This means that configurations are possible for concepts such as balances, sudo, and staking.
A second option in which a developer can use Substrate is through FRAME. This allows the user to create a customizable runtime and which can satisfy the developer’s needs.
FRAME is also used to build the Substrate Node. The FRAME option provides the users with a vast amount of freedom over the logic of the blockchain. This means that the user can change data types and select modules from a library. These modules are also known as “pallets”, and it is even possible to create and add custom pallets to the developer’s chain.
Lastly, the developer can also choose to use Substrate Core. As we mentioned above, the FRAME system allows the user to create a runtime with the help of pre-built modules and custom pallets. It is possible to ignore FRAME entirely and build a runtime from scratch. Then it is possible to design a runtime using any language that has the ability to target Wasm.
If a runtime works with the Node’s abstract block logic, it is then possible to create a new genesis block using WebAssembly (commonly known as Wasm). After this, the user can launch the chain with the Substrate application. If the runtime is not designed to work with the Node’s abstract block logic, then the client’s block authoring logic itself must be altered. This option is the most challenging and complex of the ways in which someone can use Substrate. However, with the complexity, there is also more freedom to innovate, which can be beneficial for the developer of the chain.
As the popularity and the public knowledge of cryptocurrency and blockchain increases, the interest in blockchain spikes as well. The demand for blockchain has never been higher, which means that the supply needs to be equal to its counterpart. More and more people are getting aware of blockchain technology, but they are still unaware of how it actually works.
Blockchain can be complex and challenging to understand for the uninitiated. And without understanding regarding blockchain, developing one can be even harder. However, to ease the development of a blockchain, Parity provides the world with the Substrate framework. The purpose of the framework is to make the development of a blockchain easier.
The framework is of a modular design, which means the user can construct a blockchain using a tested library and add the components that are sought after to supply the chain’s needs.
The framework supplies the user with several essential components that are useful for the chain, such as storage, runtime, P2P networks, and consensus engines. Along with this, it is possible to use the framework in three different ways: either through the Node, the FRAME, or from the basic Core. This means that it is possible to develop a chain with pre-developer runtimes or create one from scratch with the Substrate Core. However, depending on the alternative selected, the degree of freedom varies, and so does the difficulty of the development process.
If you are interested in learning more about crypto or the blockchain technology behind these virtual currencies, then feel free to tune in to the number one blockchain education platform Ivan on Tech Academy. The academy offers basic as well as more advanced blockchain courses. So it does not matter if you are new to programming or a more experienced developer; there are courses for you!