Career, Tech Knowledge, Web3

Web 3.0 development with Substrate. Part 2: Configuring blockchain nodes.

This post is part of a series on Web 3.0 Development with Substrate.

A blockchain is a network of nodes: without nodes, a blockchain is nothing but a centralised (and vulnerable) digital ledger. A node itself is a combination of hardware and software needed to manage all blockchain operations. To streamline some of these complex processes, Substrate uses a node template architecture similar to that of common web apps. In this article, we look into the back-end operations needed to run Substrate blockchain nodes.

The node template

Substrate is a multi-faceted software specifically designed for Web 3.0 development. When working with Substrate, you will be operating across three different areas: within the Substrate framework (code), on the Substrate client (node), for the Substrate runtime (blockchain). This means that you can choose to specialise in one area when working as part of a blockchain development team or work alone on the full-stack of your blockchain projects. The inherent flexibility of the Substrate Framework makes it easy to start with very basic knowledge and slowly build your own ability to develop complex blockchain logic.

Substrate nodes scalability.
Substrate nodes’ back-end operations scale in technicality and modularity.
[Adapted from a graph from Parity Technologies]

At a very basic level, a Substrate node is a project that you manage through the Substrate Framework. It is made up of standardised directories and components called the node template that will be used to build the client on your hardware. Within this template, the directories node, runtime and pallets constitute the bulk of the back-end code.

Compiling a node project

The node directory contains most of the components needed to create the consensus mechanism (service), to deploy the initial blockchain (chain specification), and to communicate with other nodes (remote procedure call/RPC). Most of the Substrate blockchain scripts and utilities are built from this folder and are dependent on the node template runtime to successfully compile.

Core directories of the Substrate node template.
Overview of the Substrate node template.

The runtime directory holds the configuration files that are used to set the blockchain logic over time. The runtime is built with the FRAME framework, which gives another layer of abstraction much-needed to develop a wider variety of blockchains. It is important to note that the runtime from the node template is assembled from a selection of FRAME pallets and thus offer a minimum viable client ready for in-house customisations. Rust crates and Wasm binaries are configured from this folder and are dependent on the pallet template to successfully compile.

Customising the runtime via a JSON file.

The pallets directory hosts the template that is used to manage the FRAME pallets of the runtime. FRAME pallets themselves are made of essential components that keep a record of the blockchain state (storage), update the blockchain state (dispatchables), broadcast changes in the blockchain runtime (events), publish operational mishaps (errors) and define specific pallet dependencies (traits).

Launching a live blockchain

As we have seen, the ready-made node template allows developers to save a lot of time on Web 3.0 development operations, as there is no need to build a blockchain from scratch. Instead, the focus is on making decisions relative to which type of node and which kind of blockchain will suit your project. With Substrate, there are two major launch modes: single-node and multi-node.

Launch parameters for a Development chain node.
[Courtesy of Parity Technologies]

In a single-node setting, you can run your chain specification in development mode, either as a temporary node or with a permanent state, but the RPC functionality will be disabled. This launch is useful for experimenting with custom pallets and exploring common block parameters (block time, hash, proposal, finality).

In a multi-node setting, you will be running your chain specification in local testnet mode, either for a Private Network or a Permissioned Network, and the RPC functionality will be available. This launch is essential for exploring nodes’ roles (validator, well-known node, off-chain worker, etc) and observing their communication protocols (websocket ports, libp2p node keys and peer ids, telemetry, etc)

Local Testnet node.
Launch parameters for a Local Testnet node (Private network).
[Courtesy of Parity Technologies]

Since the Substrate node itself is built like an application, customising the base layer of an existing Substrate blockchain to extend its functionality becomes an exercise in creativity and efficiency. Substrate’s load-and-play approach to Web 3.0 development is further enhanced by high-end utilities and libraries that produce the node’s interface. These will be detailed in Part 3.


Substrate Developer (Git)Hub: Substrate Node Template Blockchain Nodes