15 releases (3 stable)

3.0.0 Feb 10, 2021
2.0.1 Jan 11, 2021
2.0.0 Sep 22, 2020
2.0.0-rc5 Jul 24, 2020
2.0.0-alpha.5 Mar 24, 2020

#534 in Magic Beans

Download history 1681/week @ 2021-08-08 1361/week @ 2021-08-15 2083/week @ 2021-08-22 1183/week @ 2021-08-29 707/week @ 2021-09-05 1822/week @ 2021-09-12 1107/week @ 2021-09-19 1042/week @ 2021-09-26 1323/week @ 2021-10-03 1503/week @ 2021-10-10 1394/week @ 2021-10-17 1110/week @ 2021-10-24 848/week @ 2021-10-31 334/week @ 2021-11-07 164/week @ 2021-11-14 335/week @ 2021-11-21

7,131 downloads per month
Used in 2 crates (via suntime)


19K SLoC

Sudo Module


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.


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.


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:

use frame_support::{decl_module, dispatch};
use frame_system::ensure_root;

pub trait Config: frame_system::Config {}

decl_module! {
    pub struct Module<T: Config> for enum Call where origin: T::Origin {
		#[weight = 0]
        pub fn privileged_function(origin) -> dispatch::DispatchResult {

            // do something...


Genesis Config

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

Related Modules

License: Apache-2.0


~123K SLoC