55 releases (36 major breaking)

38.0.0 Sep 26, 2024
37.0.0 Jul 18, 2024
36.0.0 Jul 12, 2024
35.0.0 Jun 24, 2024
2.0.0-alpha.5 Mar 24, 2020

#12 in #pallet

Download history 2204/week @ 2024-07-29 2053/week @ 2024-08-05 3136/week @ 2024-08-12 2928/week @ 2024-08-19 2273/week @ 2024-08-26 2079/week @ 2024-09-02 2528/week @ 2024-09-09 2608/week @ 2024-09-16 3458/week @ 2024-09-23 3193/week @ 2024-09-30 2155/week @ 2024-10-07 3087/week @ 2024-10-14 4119/week @ 2024-10-21 3671/week @ 2024-10-28 3195/week @ 2024-11-04 22201/week @ 2024-11-11

33,402 downloads per month
Used in 35 crates (17 directly)

Apache-2.0

2MB
37K SLoC

Sudo Module

Overview

The Sudo module allows for a single account (called the "sudo key") to execute dispatchable functions that require a Root call or designate a new account to replace them as the sudo key. Only one account can be the sudo key at a time.

Interface

Dispatchable Functions

Only the sudo key can call the dispatchable functions from the Sudo module.

  • sudo - Make a Root call to a dispatchable function.
  • set_key - Assign a new account to be the sudo key.

Usage

Executing Privileged Functions

The Sudo module itself is not intended to be used within other modules. Instead, you can build "privileged functions" (i.e. functions that require Root origin) in other modules. You can execute these privileged functions by calling sudo with the sudo key account. Privileged functions cannot be directly executed via an extrinsic.

Learn more about privileged functions and Root origin in the Origin type documentation.

Simple Code Snippet

This is an example of a module that exposes a privileged function:

#[frame_support::pallet]
pub mod pallet {
    use super::*;
    use frame_support::pallet_prelude::*;
    use frame_system::pallet_prelude::*;

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

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

    #[pallet::call]
    impl<T: Config> Pallet<T> {
        #[pallet::weight(0)]
        pub fn privileged_function(origin: OriginFor<T>) -> DispatchResult {
            ensure_root(origin)?;

            // do something...

            Ok(())
        }
    }
}

Genesis Config

The Sudo module depends on the GenesisConfig. You need to set an initial superuser account as the sudo key.

License: Apache-2.0

Release

Polkadot SDK stable2409

Dependencies

~17–32MB
~531K SLoC