referrerpolicy=no-referrer-when-downgrade

Crate polkadot_sdk_frame

Source
Expand description

§FRAME

  ______   ______    ________   ___ __ __   ______
 /_____/\ /_____/\  /_______/\ /__//_//_/\ /_____/\
 \::::_\/_\:::_ \ \ \::: _  \ \\::\| \| \ \\::::_\/_
  \:\/___/\\:(_) ) )_\::(_)  \ \\:.      \ \\:\/___/\
   \:::._\/ \: __ `\ \\:: __  \ \\:.\-/\  \ \\::___\/_
    \:\ \    \ \ `\ \ \\:.\ \  \ \\. \  \  \ \\:\____/\
     \_\/     \_\/ \_\/ \__\/\__\/ \__\/ \__\/ \_____\/

Framework for Runtime Aggregation of Modularized Entities: Substrate’s State Transition Function (Runtime) Framework.

§Usage

This crate is organized into 3 stages:

  1. preludes: prelude, testing_prelude, runtime::prelude, benchmarking::prelude, and weights_prelude.
  2. domain-specific modules, like traits, hashing, arithmetic and derive.
  3. Accessing frame/substrate dependencies directly: deps.

The main intended use of this crate is through preludes, which re-export most of the components needed for pallet development. Domain-specific modules serve as a backup for organization, and deps provides direct access to all dependencies if needed.

§Example Usage

use polkadot_sdk_frame as frame;

#[frame::pallet]
pub mod pallet {
	use frame::prelude::*;
	// ^^ using the prelude!

	#[pallet::config]
	pub trait Config: frame_system::Config {}

	#[pallet::pallet]
	pub struct Pallet<T>(_);
}

#[cfg(test)]
pub mod tests {
	use frame::testing_prelude::*;
}

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking {
	use frame::benchmarking::prelude::*;
}

pub mod runtime {
	use frame::runtime::prelude::*;
}

§Features

This crate uses a runtime feature to include all types and tools needed to build FRAME-based runtimes. For runtime development, import it as:

polkadot-sdk-frame = { version = "foo", features = ["runtime"] }

If you just want to build a pallet instead, import it as

polkadot-sdk-frame = { version = "foo" }

§Prelude Relationships

The preludes have overlapping imports for convenience:

  • testing_prelude includes prelude and runtime::prelude
  • runtime::prelude includes prelude
  • benchmarking::prelude includes prelude

§Naming

Please note that this crate can only be imported as polkadot-sdk-frame or frame. This is due to compatibility matters with frame-support.

A typical pallet’s Cargo.toml using this crate looks like:

[dependencies]
codec = { features = ["max-encoded-len"], workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame = { workspace = true, features = ["runtime"] }

[features]
default = ["std"]
std = [
	"codec/std",
	"scale-info/std",
	"frame/std",
]
runtime-benchmarks = [
	"frame/runtime-benchmarks",
]
try-runtime = [
	"frame/try-runtime",
]

§Documentation

For more detailed documentation and examples, see polkadot_sdk_frame.

Re-exports§

Modules§

  • All account management related traits.
  • The arithmetic types used for safe math.
  • Prelude to be included in the benchmarking.rs of a pallet.
  • Access to all of the dependencies of this crate. In case the prelude re-exports are not enough, this module can be used.
  • All derive macros used in frame.
  • All hashing related components.
  • Macros used within the main pallet macro.
  • The main prelude of FRAME.
  • All of the types and tools needed to build FRAME-based runtimes.
  • The main testing prelude of FRAME.
  • All token related types and traits.
  • All traits often used in FRAME pallets.
  • This is already part of the prelude.
  • Prelude to be included in the weight.rs of each pallet.

Attribute Macros§