Crate pallet_sudo

source ·
Expand description

Sudo Pallet


The Sudo pallet 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 pallet.

  • 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 pallet itself is not intended to be used within other pallets. Instead, you can build “privileged functions” (i.e. functions that require Root origin) in other pallets. 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 pallet that exposes a privileged function:

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

	pub struct Pallet<T>(_);

	pub trait Config: frame_system::Config {}

	impl<T: Config> Pallet<T> {
        pub fn privileged_function(origin: OriginFor<T>) -> DispatchResult {

            // do something...


Signed Extension

The Sudo pallet defines the following extension:

  • CheckOnlySudoAccount: Ensures that the signed transactions are only valid if they are signed by sudo account.

Genesis Config

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



  • The pallet module in each FRAME pallet hosts the most important items needed to construct this pallet.
  • Autogenerated weights for pallet_sudo


  • Ensure that signed transactions are only valid if they are signed by sudo account.