Recipes - A Hands-On Cookbook for Aspiring Blockchain Chefs

Overview

Substrate Recipes ๐Ÿด ๐Ÿ˜‹ ๐Ÿด

Build Status

Lines of Code Try on playground

A Hands-On Cookbook for Aspiring Blockchain Chefs

Get Started

Ready to roll up your sleeves and cook some blockchain? Read the book online at substrate.recipes ๐Ÿ˜‹

Repository Structure

There are five primary directories in this repository:

  • Text: Source of the book written in markdown. This text describes the code in the other three directories.
  • Pallets: Pallets for use in FRAME-based runtimes.
  • Runtimes: Runtimes for use in Substrate nodes.
  • Consensus: Consensus engines for use in Substrate nodes.
  • Nodes: Complete Substrate nodes ready to run.

The book is built with mdbook and deployed via github pages.

Building This Book Locally

Building the book requires mdBook, ideally the same version that rust-lang/rust uses in this file. To get it:

$ cargo install mdbook --vers [version-num]

To build the book, type:

$ mdbook build

The output will be in the book subdirectory. To check it out, open up book/index.html in a web browser, or to serve the book locally, type:

$ mdbook serve

The default address to view the book will be located at http://localhost:3000 .

License

The Substrate Recipes are GPL 3.0 Licensed It is open source and open for contributions.

Using Recipes in External Projects

The pallets and runtimes provided here are tested and ready to be used in other Substrate-based blockchains. The big caveat is that you must use the same upstream Substrate version throughout the project.

Comments
  • Upgrade Recipes to Substrate 3.0

    Upgrade Recipes to Substrate 3.0

    This Pull Request updates the Substrate Recipes to use the published Substrate 3.0 crates along with other ecosystem updates such as parity-scale-codec, substrate-wasm-builder, and substrate-fixed.

    All code is compiling and passing tests locally. We just have to get CI sorted out. Thanks @jimmychu0807 and @sacha-l for the help.

    Checklist:

    • [x] Make all pallets compile
    • [x] Make all runtimes compile
    • [x] Make all nodes compile
    • [x] Make all tests pass
    • [x] General code quality review and cleanup
    • [x] Fix links
    • [x] Update writeups
    new recipe ๐Ÿณ vision ๐Ÿ‘€ wip recipeโฐ 
    opened by JoshOrndorff 17
  • Looking forward to upgrade some pallets to frame v2

    Looking forward to upgrade some pallets to frame v2

    Hello,

    I see that all the recipes still using frame v1, so I thought I could upgrade some of them to frame v2. The only issue that I have is when I import a pallet with v2 into kitchen-node I have these conflicts: Any idea why it happens? What should I upgrade? Screenshot 2021-07-25 at 16 26 49

    opened by herou 15
  • basic-pow node doesn't mine new Blocks?!

    basic-pow node doesn't mine new Blocks?!

    Hi everyone, after successfully compiling the node, i started it but it cannot mine new Blocks, it prepared an new Block but never imported it, any idea how to further debug that issue?!

    Node Name: basic-pow Node Version: 3.0.0 Commit: commit 53f7ce1b17c7c66ebe04d5a57502d2b6e59fe48a (HEAD -> master, origin/master, origin/HEAD) Author: Joshy Orndorff [email protected] Date: Wed Apr 14 23:53:04 2021 -0400

    Cargo Version: cargo 1.49.0-nightly (dd83ae55c 2020-10-20) Rustup: rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24) OS: Ubuntu 20.04.2 LTS

    Screenshot_2021-04-22_17-51-47

    opened by Mhnd3 12
  • Charity can't donate 499 femto at first

    Charity can't donate 499 femto at first

    I know that to make the pallet account works, it must have minimum_balance currency which in my point is ensured by add_extra_genesis in

    decl_storage! {
    	trait Store for Module<T: Trait> as SimpleTreasury {
    		// No storage items of our own, but we still need decl_storage to initialize the pot
    	}
    	add_extra_genesis {
    		build(|_config| {
    			// Create the charity's pot of funds, and ensure it has the minimum required deposit
    			let _ = T::Currency::make_free_balance_be(
    				&<Module<T>>::account_id(),
    				T::Currency::minimum_balance(),
    			);
    		});
    	}
    }
    

    when I call donate method to donate 499 femto, it fails of transfer currency. But when I donate 500 femto, it success. I think it's affected by pub const ExistentialDeposit: u128 = 500;. But if add_extra_genesis works, the pallet account should have minimum_balance before I send the donate transaction. I am not sure this is the correct behavior or not? If it is, then why should it fail? Am I miss something.

    opened by manxiaqu 11
  • Hybrid Consensus Mode: Essential task `grandpa-voter` failed. Shutting down service.

    Hybrid Consensus Mode: Essential task `grandpa-voter` failed. Shutting down service.

    When following the tutorial here https://substrate.dev/docs/en/tutorials/start-a-private-network/customchain, I successfully get two nodes up and running and talking to each-other in mining mode, then proceed to try and turn on GRANDPA voting.

    The documents specify that I should connect to a node and call author with keyType gran and enter the mnemonic and the public key generated by subkey; once those calls are in, I should restart the nodes and they will begin to function as finalizing nodes.

    This doesn't seem to work; instead, I get:

    % target/release/hybrid-consensus \
    --base-path /tmp/node02 \
      --chain ./customSpecRaw.json \
      --port 30334 \
      --ws-port 9945 \
      --rpc-port 9934 \
      --telemetry-url 'wss://telemetry.polkadot.io/submit/ 0' \
      --validator \
      --rpc-methods=Unsafe \
      --name MyNode02 \
      --bootnodes /ip4/127.0.0.1/tcp/9615/p2p/12D3KooWQAmVsNzwugd1Z62YPa467iBH621cXCCeRg5H2NwGVtog
    2020-08-31 16:50:57 Hybrid Consensus Node (PoW and Grandpa)
    2020-08-31 16:50:57 โœŒ๏ธ  version 2.0.0-rc5-42ac927-x86_64-macos
    2020-08-31 16:50:57 โค๏ธ  by Substrate DevHub <https://github.com/substrate-developer-hub>, 2019-2020
    2020-08-31 16:50:57 ๐Ÿ“‹ Chain specification: Transformer Chain
    2020-08-31 16:50:57 ๐Ÿท  Node name: MyNode02
    2020-08-31 16:50:57 ๐Ÿ‘ค Role: AUTHORITY
    2020-08-31 16:50:57 ๐Ÿ’พ Database: RocksDb at /tmp/node02/chains/transformer/db
    2020-08-31 16:50:57 โ›“  Native runtime: minimal-grandpa-runtime-1 (minimal-grandpa-runtime-1.tx1.au1)
    2020-08-31 16:50:57 ๐Ÿ“ฆ Highest known block at #289
    2020-08-31 16:50:57 Using default protocol ID "sup" because none is configured in the chain specs
    2020-08-31 16:50:57 ๐Ÿท  Local node identity is: 12D3KooWLN9dYLXF2Coo8Dmx7Zu1KHpeQY4d62gXsrSzqf7u2xYV (legacy representation: QmYSe7ZXfAWn46yHK5QEeJtYMM9nWNZVQJc77QVauVa7Sh)
    2020-08-31 16:50:57 ๐Ÿ™Œ Starting consensus session on top of parent 0xe8731b6e26e991af0996cc9170dd7e8f0807beab56864f29c144a2a9c83b4cb5
    2020-08-31 16:50:57 Timeout fired waiting for transaction pool at block #289. Proceeding with production.
    2020-08-31 16:50:57 ๐ŸŽ Prepared block for proposing at 290 [hash: 0x3d3123065aff70540ce0f47c37f8d315916ba82c742cd69b79d42e617d54e18a; parent_hash: 0xe873โ€ฆ4cb5; extrinsics (1): [0x940fโ€ฆ2d3d]]
    2020-08-31 16:50:58 ๐Ÿ™Œ Starting consensus session on top of parent 0xb5f942b91950190301044586e8b9b329887d43474a0098ed7d56a3d4fb625dea
    2020-08-31 16:50:58 โœจ Imported #290 (0xb5f9โ€ฆ5dea)
    2020-08-31 16:50:58 ๐ŸŽ Prepared block for proposing at 291 [hash: 0xca0cde13e7cd4facba69d51cbeb1a242720bd8d9a511bef14c09aef43159e29a; parent_hash: 0xb5f9โ€ฆ5dea; extrinsics (1): [0x5d30โ€ฆ6741]]
    2020-08-31 16:50:58 Essential task `grandpa-voter` failed. Shutting down service.
    Error: Input("Essential task failed.")
    

    How do I debug this?

    opened by vessenes 10
  • cargo build --release does not properly build kitchen node

    cargo build --release does not properly build kitchen node

    Just tried following instructions to run a kitchen node. https://substrate.dev/recipes/base/runnode.html

    However seem to get the following error when running cargo build --release

    Error:

    araa@MAC127 ~/Desktop/recipes/kitchen/node (master) (โ‚ฟ) cargo build --release
        Updating git repository `https://github.com/paritytech/substrate.git`
        Updating crates.io index
    error: no matching package named `srml-babe` found
    location searched: https://github.com/paritytech/substrate.git
    required by package `super-runtime v2.0.0 (/Users/araa/Desktop/recipes/kitchen/runtimes/super-runtime)`
        ... which is depended on by `kitchen-node v2.0.0 (/Users/araa/Desktop/recipes/kitchen/node)`
    
    opened by araa47 10
  • cargo check modules, runtimes, and node.

    cargo check modules, runtimes, and node.

    This is a draft of getting CI to check each module. My approach so far is adding a line in the .circleci/config.yml for each module. This has a significant disadvantage that the builds don't share a common target directory so the common stuff gets recompiled every time. I think the solution involves workspaces. Check out how the main substrate repo organizes all those modules into the srml directory. But I'm not sure how to do that.

    I'd also like to get the cacheing working so the CI doesn't have to download so much stuff each time. @jimmychu0807 I know you took care of the caching on the front end template. Any advice to share?

    opened by JoshOrndorff 10
  • Most links to Substrate Playground are not working

    Most links to Substrate Playground are not working

    Tried on the following pages:

    • https://substrate.dev/recipes/storage-maps.html
    • https://substrate.dev/recipes/events.html
    • https://substrate.dev/recipes/cache.html

    Clicking on the "Playground Try It" button returns me the following message:

    Screenshot 2021-03-31 at 12 26 01

    opened by jimmychu0807 9
  • Missing type for accuracy

    Missing type for accuracy

    I just did a fresh clone of the 'master' branch of this repo and got the following error when i ran cargo build --release. I haven't investigated why yet, but just thought I'd report it. rustc 1.52.0-nightly (35dbef235 2021-03-02)

         Compiling primitive-types v0.7.2
      error[E0282]: type annotations needed
          --> /Users/ls2/.cargo/registry/src/github.com-1ecc6299db9ec823/sp-arithmetic-2.0.0/src/fixed_point.rs:541:9
           |
      541  |                   let accuracy = P::ACCURACY.saturated_into();
           |                       ^^^^^^^^ consider giving `accuracy` a type
      ...
      1595 | / implement_fixed!(
      1596 | |     FixedI64,
      1597 | |     test_fixed_i64,
      1598 | |     i64,
      ...    |
      1601 | |     "_Fixed Point 64 bits signed, range = [-9223372036.854775808, 9223372036.854775807]_",
      1602 | | );
           | |__- in this macro invocation
           |
           = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
    
      error[E0282]: type annotations needed
          --> /Users/ls2/.cargo/registry/src/github.com-1ecc6299db9ec823/sp-arithmetic-2.0.0/src/fixed_point.rs:541:9
           |
      541  |                   let accuracy = P::ACCURACY.saturated_into();
           |                       ^^^^^^^^ consider giving `accuracy` a type
      ...
      1604 | / implement_fixed!(
      1605 | |     FixedI128,
      1606 | |     test_fixed_i128,
      1607 | |     i128,
      ...    |
      1611 | |         [-170141183460469231731.687303715884105728, 170141183460469231731.687303715884105727]_",
      1612 | | );
           | |__- in this macro invocation
           |
           = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
    
      error[E0282]: type annotations needed
          --> /Users/ls2/.cargo/registry/src/github.com-1ecc6299db9ec823/sp-arithmetic-2.0.0/src/fixed_point.rs:541:9
           |
      541  |                   let accuracy = P::ACCURACY.saturated_into();
           |                       ^^^^^^^^ consider giving `accuracy` a type
      ...
      1614 | / implement_fixed!(
      1615 | |     FixedU128,
      1616 | |     test_fixed_u128,
      1617 | |     u128,
      ...    |
      1621 | |         [0.000000000000000000, 340282366920938463463.374607431768211455]_",
      1622 | | );
           | |__- in this macro invocation
           |
           = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
    
      error: aborting due to 3 previous errors
    
    
    opened by ltfschoen 9
  • Remove clippy warning suppression

    Remove clippy warning suppression

    In https://github.com/substrate-developer-hub/recipes/pull/305/commits/062d8f74a3e8bf5c5d3b7b1294488272c58a1849 I added several warning suppression lines. They were necessary due to the implementation of impl_runtime_apis! and decl_runtime_apis!. This has now been fixed upstream in Substrate https://github.com/paritytech/substrate/pull/6540

    Next time we update to a more recent Substrate, these lines should be removed.

    mentor available๐Ÿฑโ€๐Ÿ’ป organization ๐Ÿ”จ 
    opened by JoshOrndorff 9
  • Why it takes so much time to have a response from you guys?

    Why it takes so much time to have a response from you guys?

    Hello,

    May you already know (at least you have seen my name on PR and issues) me. Something that I do not understand why it takes 4-5 days to have a single response from you guys. I like to contribute to this repo but the responses's delay is making everything slower. I would really appreciate it if you do something about this.

    opened by herou 8
  • Recipe Book not updated as per FRAME v2

    Recipe Book not updated as per FRAME v2

    I just found that the book is not updated as per FRAME v2.

    So, I shall be working on this as I make my learning.

    For any suggestion, please reach out to me.

    opened by abhi3700 1
  • How can I upgrade versions of packages?

    How can I upgrade versions of packages?

    My current substrate node version is 4.0.0-dev. And I am going to add offchain worker function on my current node project. I have added the ocw-demo pallet on pallets folder. And then, when I run the cargo check , I am getting this error.

    image

    How can I solve this problem? Where can I find the exact version of ocw-demo pallet for substrate version "4.0.0-dev"? Please help me!!!

    opened by WB-Expert5007 0
  • Bump thread_local from 1.1.3 to 1.1.4

    Bump thread_local from 1.1.3 to 1.1.4

    Bumps thread_local from 1.1.3 to 1.1.4.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies rust 
    opened by dependabot[bot] 0
  • error: duplicate lang item in crate std (which serde depends on): panic_impl. and error: duplicate lang item in crate std (which serde depends on): oom.

    error: duplicate lang item in crate std (which serde depends on): panic_impl. and error: duplicate lang item in crate std (which serde depends on): oom.

    How do I fix this error?

    error: duplicate lang item in crate std (which serde depends on): panic_impl. | = note: the lang item is first defined in crate sp_io (which ocw_demo depends on) = note: first definition in sp_io loaded from /home/kshamalka/recipes/target/release/wbuild/ocw-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-0713151cf511a047.rmeta = note: second definition in std loaded from /home/kshamalka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-4faf99cd6c5513da.rlib

    error: duplicate lang item in crate std (which serde depends on): oom. | = note: the lang item is first defined in crate sp_io (which ocw_demo depends on) = note: first definition in sp_io loaded from /home/kshamalka/recipes/target/release/wbuild/ocw-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-0713151cf511a047.rmeta = note: second definition in std loaded from /home/kshamalka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-4faf99cd6c5513da.rlib

    error: could not compile ocw-demo due to 2 previous errors warning: build failed, waiting for other jobs to finish...

    opened by KavinduShamalka 1
  • How do I fix this error?

    How do I fix this error?

    error: duplicate lang item in crate std (which serde depends on): panic_impl. | = note: the lang item is first defined in crate sp_io (which ocw_demo depends on) = note: first definition in sp_io loaded from /home/kshamalka/recipes/target/release/wbuild/ocw-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-0713151cf511a047.rmeta = note: second definition in std loaded from /home/kshamalka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-4faf99cd6c5513da.rlib

    error: duplicate lang item in crate std (which serde depends on): oom. | = note: the lang item is first defined in crate sp_io (which ocw_demo depends on) = note: first definition in sp_io loaded from /home/kshamalka/recipes/target/release/wbuild/ocw-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-0713151cf511a047.rmeta = note: second definition in std loaded from /home/kshamalka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-4faf99cd6c5513da.rlib

    error: could not compile ocw-demo due to 2 previous errors warning: build failed, waiting for other jobs to finish...

    opened by KavinduShamalka 0
Owner
Joshy Orndorff
Blockchain::{Developer, Philosopher, Chef}
Joshy Orndorff
Taking the best of Substrate Recipes and applying them to a new framework for structuring a collection of how-to guides.

Attention: This repository has been archived and is no longer being maintained. It has been replaced by the Substrate How-to Guides. Please use the Su

Substrate Developer Hub 35 Oct 17, 2022
A high performance blockchain kernel for enterprise users.

English | ็ฎ€ไฝ“ไธญๆ–‡ What is CITA CITA is a fast and scalable blockchain kernel for enterprises. CITA supports both native contract and EVM contract, by whi

CITAHub 1.3k Dec 22, 2022
The Nervos CKB is a public permissionless blockchain, and the layer 1 of Nervos network.

Nervos CKB - The Common Knowledge Base master develop About CKB CKB is the layer 1 of Nervos Network, a public/permissionless blockchain. CKB uses Pro

Nervos Network 1k Dec 30, 2022
The Phala Network Blockchain, pRuntime and the bridge.

Phala Blockchain Phala Network is a TEE-Blockchain hybrid architecture implementing Confidential Contract. This repo includes: node/: the main blockch

Phala Network 314 Jan 6, 2023
Substrate: The platform for blockchain innovators

Substrate ยท Substrate is a next-generation framework for blockchain innovation ?? . Trying it out Simply go to substrate.dev and follow the installati

Parity Technologies 7.7k Dec 30, 2022
An extensible open-source framework for creating private/permissioned blockchain applications

Exonum Status: Project info: Community: Exonum is an extensible open-source framework for creating blockchain applications. Exonum can be used to crea

Exonum 1.2k Jan 1, 2023
Local blockchain for Free TON DApp development and testing.

TON OS Startup Edition Local blockchain for Free TON DApp development and testing. Have a question? Get quick help in our channel: TON OS Startup Edit

TON Labs 35 Jan 2, 2023
A value transfer bridge between the Monero blockchain and the Secret Network.

Secret-Monero-Bridge A value transfer bridge between the Monero blockchain and the Secret Network. Proof-of-Concept Video Demonstration: https://ipfs.

null 28 Dec 7, 2022
C++ `std::unique_ptr` that represents each object as an NFT on the Ethereum blockchain

C++ `std::unique_ptr` that represents each object as an NFT on the Ethereum blockchain

null 1.9k Dec 28, 2022
HyperCube is a free and open source blockchain project for everyone to use.

XPZ Public Chain HyperCube is a free and open source blockchain project for everyone to use. ๆ—ฅๆœฌ่ชž ็ฎ€ไฝ“ไธญๆ–‡ ๆญฃ้ซ”ไธญๆ–‡ HyperCube Wiki Wha is HyperCube HyperCube i

null 949 Dec 31, 2022
๐ŸŒ The Earth Blockchain on Polkadot (archived)

Social Network Blockchain ยท The Social Network blockchain is a next-generation governance, economic, and social system for humanity built on Polkadot

social.network 18 Jan 2, 2023
High Performance Blockchain Deserializer

bitcoin-explorer bitcoin_explorer is an efficient library for reading bitcoin-core binary blockchain file as a database (utilising multi-threading). D

Congyu 18 Dec 22, 2022
Substrate blockchain generated with Substrate Startkit

Substrate Node Template A new FRAME-based Substrate node, ready for hacking ?? Getting Started This project contains some configuration files to help

HoangDuong 1 Oct 19, 2021
Substrate blockchain generated with Substrate Startkit

Substrate Node Template A new FRAME-based Substrate node, ready for hacking ?? Getting Started This project contains some configuration files to help

HoangDuong 1 Oct 19, 2021
Trinci blockchain node

TRINCI TRINCI Blockchain Node. Requirements The required dependencies to build correctly the project are the following: clang libclang-dev (ver. 11 su

Affidaty S.p.A. 5 Sep 26, 2022
A lightweight and flexible framework to build your tailored blockchain applications.

TRINCI Blockchain Core A lightweight and flexible framework to build your tailored blockchain applications. Requirements The required dependencies to

Affidaty S.p.A. 11 Sep 26, 2022
flow-rust-sdk utilizes the Flow gRPC AccessAPI to make requests on the flow blockchain.

Welcome to the Flow-Rust-SDK! We're glad to have you here. There are a few important items that we should cover real quick before you dive in. Version

null 8 Jul 26, 2022
Testing a smart contract on the Solana blockchain

Environment Setup Install Rust from https://rustup.rs/ Install Solana from https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-to

Maurice 1 Oct 25, 2021
This is the Repo used to learn blockchain development in conjusction with the CyberGen NFT Project.

Environment Setup Install Rust from https://rustup.rs/ Install Solana from https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-to

null 1 Nov 3, 2021