49 releases (30 major breaking)

32.0.0 Apr 9, 2024
31.0.0 Mar 18, 2024
30.0.0 Feb 26, 2024
29.0.0 Feb 13, 2024
2.0.0-alpha.5 Mar 24, 2020

#1335 in Magic Beans

Download history 650/week @ 2023-12-23 971/week @ 2023-12-30 1289/week @ 2024-01-06 1216/week @ 2024-01-13 1262/week @ 2024-01-20 1033/week @ 2024-01-27 996/week @ 2024-02-03 1726/week @ 2024-02-10 2506/week @ 2024-02-17 2106/week @ 2024-02-24 1585/week @ 2024-03-02 1647/week @ 2024-03-09 2158/week @ 2024-03-16 2242/week @ 2024-03-23 2567/week @ 2024-03-30 1636/week @ 2024-04-06

8,822 downloads per month
Used in 24 crates (15 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

Dependencies

~18–32MB
~517K SLoC