Written by Shawn Tabrizi
Learn the fundamentals of blockchain development by building your own Polkadot-like state machine from scratch.
RustBeginner7 lessons
This article introduces the tutorial on building a Rust-based state machine, aimed at teaching the basics of Rust, blockchain, and the Polkadot SDK. It focuses on demystifying advanced Rust features used in Substrate and explains the underlying mechanisms of code-generating macros. The tutorial is designed for beginners but recommends prior basic Rust knowledge.
Start LessonIn this section, we will build the very first logic for our state machine: a Balances Pallet.
This Pallet will manage the balances of users and allow them to transfer tokens to one another.
Along the way, you will learn about safe math, options, error handling, and more.
By the end of this section, you will have designed the logic of a simple cryptocurrency.
Start LessonIn this section, you will create the System Pallet, a low level Pallet for managing basic blockchain state.
Then you will integrate both the Balances Pallet and System Pallet into your state transition function, called the Runtime.
Start LessonIn this section, we will be harnessing the full power of Rust to create a generic and configurable Runtime.
There will be no real logical changes happening in the next steps.
Instead, we will be gradually abstracting away the concrete types defined in our Pallets, and instead structure our code to handle purely generic types.
At the end of the section, you will have a project whose structure exactly mirrors what is found in the Polkadot SDK and understand how all of it works.
Start LessonIn this next section, you will construct the core pipeline used to interact with your state machine.
We will create the block structure which contains the transactions for your state transition function, and then the function dispatch pipeline to route those transactions to the appropriate function calls.
The goal of this section is to make your existing state machine resemble a blockchain that can be extended and upgraded.
Start LessonIn this section, we will create a Proof of Existence Pallet.
We will take advantage of all the refactoring we have done so far to make it very simple to integrate this new Pallet into our existing Runtime.
There are no new concepts to learn in this section, however it will test that you understand and can reproduce all the steps and concepts learned in the previous sections.
Start LessonIn this section, we will introduce Rust Macros to our project to reduce boilerplate code and automate implementations.
You can imagine that continuing to add new Pallets to our runtime would lead to a lot of similar or redundant code.
By the end of this section, you will see how Rust Macros can automatically generate the code we have been writing, and why the Polkadot SDK uses this technique to improve developer experience and output.
Start Lesson