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
Subtensor's Pallets
Subtensor includes 27 active pallets. The most important one is SubtensorModule, which handles staking, registration, weights, and emissions.
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
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.
Calls (Inputs)
Actions you can submit to the chain (also called extrinsics). Calls take parameters, validate them, update storage, and emit events.
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.
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.
Errors (Failures)
Ways that calls can fail. Each pallet defines its own error types. When a call fails, it returns an error explaining why.
How Pallets Interact
Pallets can call each other. For example, SubtensorModule uses the Balances pallet to transfer tokens when processing stakes.