Substrate; Show Me The Code

How to use the slides - Full screen (new tab)
Slides Content
--- title: Substrate; Show Me The Code description: A hands-on dive into practical matters of substrate, such as docs, CLI and folder structure. duration: 60 minutes ---

Substrate; Show Me The Code 👨‍💻

Substrate; Show Me The Code 👨‍💻

Previous lecture was all about high level information; now we want to bridge that to real code.

A Word on Previous Versions

  • This is a brand new lecture replacing two old ones, with more focus on rust-docs.
  • Since this is the first time, I have kept the old versions around for you to look into

Cambridge-y (adj) - Overall good quality, but with rough edges or imperfections. Especially when related to PBA content.


A Word on the Rust Exam

Two main takeaways from the previous cohort:

  • Write more rust-docs, expect them to be read.
  • Extensive use of type-system, to prepare you better for FRAME.


Personally doing my best to make it hard, but reasonable, such that it prepares you best for in-depth development of Substrate.



  • This lecture will be interactive.
  • Try and learn the technique, not the specific topic.
  • Try and repeat the process later.


what I am trying to do here is to teach you how to plant a tree rather than giving you the apple.

Documentation Resources


    • substrate crate
    • WIP: frame, cumulus and polkadot crate.
  • Github
  • Substrate/Polkadot StackExchange

High level

  • Discord, Telegram, etc.

Exploring the substrate crate.


Substrate From Within

Division of substrate when seen from inside:

  1. sp
  2. sc
  3. frame/pallet/runtime


this should be covered


Substrate Binaries


alternative way is to search for [[bin]] in all toml files.


Structure of a Binary Crate

Division of a typical substrate-based project:

  1. node
    1. Contains a
    3. and more!
  2. runtime
    1. Contains a /src/ ("runtime amalgamator")
  3. more!


node is client side entry point, runtime amalgamator for the runtime.

  • looking at node-template, it only has the two.
  • node has even more
  • polkadot has even more.


Substrate CLI

Study in the docs:

  • --dev
  • --chain
  • --tmp, --base-path, purge-chain.


all commands: all args to a typical run command

But then each node can decide which subset of these it chooses, and how it implements it.

  • execution strategies
  • database type
  • logs
  • RPC
  • pruning
  • sync modes


Wasm Build + std feature.

  • How to compile to wasm?!
  • just get your std features right please!

Notes: (seen env variables, pretty useful!)


Chain Specification


raw vs not-raw

#1 Rust-Docs Tip Of All Time

  • Search traits, find implementations.
  • Examples: trait Block, trait Extrinsic, trait Header.
fn main() {
trait Config {
  type Foo: SomeTrait<Bar>


Especially in FRAME, oftentimes you have to parameterize your pallets with a pattern like above. Simply search the trait in the rust-docs, and find the implementors!

Additional Resources! 😋

Check speaker notes (click "s" 😉)


One important concept that is important to substrate-based chains, but is somewhat missing here is chain-spec. Make sure to read up about it in the substrate docs.