Skip to main content

๐Ÿ˜บ Substrate Kitties

This is a 2 part tutorial series that steps you through building a pallet for managing Substrate Kitties from scratch. Each part could take between 1.5 and 3 hours to complete depending on your level of experience with Substrate.



Welcome to the Substrate Kitties tutorial. This 2 part tutorial designed to teach you everything you need to know to build a blockchain designed to handle the creation and ownership management of Substrate Kitties. Part 1 will cover how to build the Kitties pallet, including the functionality to interact with the Kitties we create, such as transfering, buying and setting prices. Part II will cover developing the Front-end UI to interact with the blockchain we build in Part 1.


You may find it useful to come back to this page as you progress through each part โ€” just to keep track of the bigger picture.

What we're building#

In Part 1 of this tutorial, we'll intentionally keep things simple so that you can decide on how you'd like to improve your Substrate Kitties chain later on. For the purposes of what we're building, Kitties really can only do the following things:

๐Ÿ˜บ Be created either by some original source or by being bred using existing Kitties.

๐Ÿ˜ผ Be sold at a price set by their owner.

๐Ÿ˜พ Be transferred from one owner to another.

In Part 1, we'll go over:

  1. Basic setup. We'll need to spin up a Substrate node and create a custom pallet

  2. Runtime storage. We'll need a total of 3 storage items in our pallet to keep track of the amount of Kitties; their owners and a Kitty object containing a single Kitty's information.

  3. Dispatchable functions. We'll need a total of 5 dispatchable functions: create, set_price, transfer, buy_kitty and breed_kitty

  4. Private functions. We'll write 2 helper functions to handle randomness: increment_nonce and random_hash

  5. Helper functions. We'll write 2 helper functions for our dispatchable functions: mint and transfer_from.

In Part 2, we will:

  1. Create a UI for interacting with our pallet's storage items. We'll connect to a React front-end template and create the UI for each dispatchable call.

  2. Enhance our UX with Polkadot JS API.

What we won't cover#

The following fall outside the scope of this tutorial:

  • Writing tests for our pallet.

  • Declaring a configuration for the genesis of our chain.

    You can refer to the how-to guides on how to do this once you've completed this tutorial series.


Follow each step at your own pace โ€” the goal is for you to learn and the best way to do that is to try it yourself! Use the side panel to write your code as you follow along (coming soon). Before moving on from one section to the next, make sure your pallet builds without any error.

You'll be writing most of the code yourself! Use the template files here to help you complete each part.

Learning outcomes#

โžก๏ธ Write and integrate a custom FRAME pallet to your runtime.

โžก๏ธ Use structs in storage and how to create and update storage items.

โžก๏ธ Write pallet extrinsics and helper functions.

โžก๏ธ Use the PolkadotJS API to connect a Substrate node to a custom a front-end.

Was this guide useful?