Learn / Understanding Pallets

Understanding Pallets

Pallets are Substrate's building blocks. Each pallet is a module that groups related functionality together.

What is a Pallet?

A pallet is a self-contained module in a Substrate blockchain. Each pallet is a plugin that adds specific functionality, and can define:

  • Storage. On-chain state that persists between blocks
  • Calls. Functions users can invoke (extrinsics)
  • Events. Notifications emitted when things happen
  • Errors. Ways that calls can fail
  • Constants. Fixed values baked into the runtime
Pallet Structure
Pallet (e.g., SubtensorModule)
Storage
Calls
Events
Errors
Constants

Subtensor's Pallets

Subtensor includes 27 active pallets. The most important one is SubtensorModule, which handles staking, registration, weights, and emissions.

SubtensorModule

The core pallet. Handles staking , neuron registration, weights , emissions , and subnet management.

59 active calls 112 active events 188 active storage items

Balances

Token balances, transfers, and account management

System

Block numbers, account nonces, runtime upgrades

AdminUtils

Sudo operations, network parameter updates

Commitments

Commit-reveal schemes for weight privacy

View all 27 pallets in Reference

Pallet Anatomy

Each pallet contains five types of items. Understanding these is key to working with Subtensor.

Events (Outputs)

Notifications emitted when something happens on-chain. Events are how you know a call succeeded and what changed. They're indexed and searchable.

StakeAdded(coldkey, hotkey, tao_amount, alpha_amount, netuid, alpha_price)

Calls (Inputs)

Actions you can submit to the chain (also called extrinsics). Calls take parameters, validate them, update storage, and emit events.

add_stake(hotkey, netuid, amount)

Storage (State)

On-chain state that persists between blocks. Storage is what calls modify and what you can query. Each item has a key pattern and value type.

Alpha[hotkey][coldkey][netuid] → u128

Constants (Configuration)

Fixed values baked into the runtime. Can only change with a runtime upgrade. Used for network parameters like block time or max weight values.

BlockWeights.max_block = 2_000_000_000_000

Errors (Failures)

Ways that calls can fail. Each pallet defines its own error types. When a call fails, it returns an error explaining why.

NotEnoughBalanceToStake: "Coldkey does not have enough balance"

How Pallets Interact

Pallets can call each other. For example, SubtensorModule uses the Balances pallet to transfer tokens when processing stakes.

Example: add_stake call flow
User calls add_stake()
SubtensorModule validates inputs
Calls Balances.transfer()
Updates Alpha storage
Emits StakeAdded event