Written by Shawn Tabrizi
Learn the fundamentals of blockchain development by building your own Polkadot-like state machine from scratch.
RustBeginner7 lessons
Welcome to the Rust State Machine tutorial.
This is a guided tutorial intended to teach readers the basics of Rust, Blockchain, and eventually the inner workings of the Polkadot SDK.
The hardest part of building your first blockchain using the Polkadot SDK is navigating the advance Rust features used by Substrate, and understanding the underlying magic behind various macros which generate code for you.
This tutorial directly addresses this by having you build a completely vanilla Rust project which does all the same tricks as the Polkadot SDK, so you know first hand what is going on behind the scenes.
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.
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