The Substrate Blockchain Framework

Substrate Framework

Substrate was born from the vision that developers shouldn’t have to recreate fundamentals when building and optimizing a blockchain.

A […] flexible, open, interoperable, and future-proof blockchain framework.

During my Ph.D. thesis, the goal is to build, develop and explore blockchain/DLT solutions that match a vehicle ecosystem use case.
Many times I’ve faced the same issue: Which blockchain technology to use? Ethereum, Hyperledger Sawtooth, EOSIO, etc.? Maybe Substrate Framework is the solution?

Motivation

If we count all original and project forks, there are over thousands of blockchain projects (e.g. 105K projects on Github). But choosing an existing blockchain technology locks you in a limited set of features, properties, and performances that can only evolve if the community behind it upgrades the software. Thus, we need a customizable blockchain.

Here comes Substrate: a blockchain framework
Substrate was made after the creation of Polkadot (a blockchain relay network). Thanks, Polkadot!

And so, from Polkadot, came Substrate… by Shawn Tabrizi

Overview of Substrate

Substrate is a blockchain framework with many typical blockchain pluggable features thanks to the FRAME modules (also called pallets) and a custom runtime.

The main advantage of Substrate combined with Polkadot is multichain. Substrate blockchains can be created (i.e. parachains) and connected to the Polkadot relay chain: Creating a multichain ecosystem. A lot more detailed vision of the project is explained by Gavin Wood here.

Building a blockchain pallet

The substrate-node-template basic blockchain node example provides us with a perfect “template” pallet example.
The Skeleton of a pallet is composed of 7 sections:

  • Imports and Dependencies
  • Declaration of the Pallet type
  • Runtime Configuration Trait
  • Runtime Storage
  • Runtime Events
  • Hooks
  • Extrinsics

The code for the template pallet is as follows:

Next step: Customization

My goal was to build a custom pallet to store vehicle data crash hashes with a basic authority model with an admin (creating factories), factories (creating vehicles), and vehicles combined with drivers can send transactions. To know more about the use case you can visit a previous post.

Car transaction processor business logic
Car transaction processor business logic [1]

We will have three storage items: the factory list, the cars list, and the crashes list.

The code resulting from such logic can be coded as follows:

Test the pallet

By using the Polkadot JS app I have tested the pallet successfully. It is possible to execute pallet actions using the extrinsic tool.

Execute extrinsic with Polkadot JS App

Conclusion

Substrate is a huge framework. I’ve just shown in this post the basic customization of the template blockchain node. Many more features can be discovered in the tutorials here.

Polkadot and Substrate to the moon!

  1. L. Gerrits, R. Kromes and F. Verdier, “A True Decentralized Implementation Based on IoT and Blockchain: a Vehicle Accident Use Case,” 2020 International Conference on Omni-layer Intelligent Systems (COINS), 2020, pp. 1-6, doi: 10.1109/COINS49042.2020.9191405.

Leave a Comment