Build a composable staking pallet for your runtime.
Write a pallet that allows users to lock funds.
- Conviction voting.
LockableCurrency trait can be very useful in the context of economic systems that enforce accountability by collateralizing fungible resources.
Substrate's staking pallet makes use of the same trait to handle locked funds in time-based increments. In
this guide, we will make use of it in our own custom pallet.
Import the following traits:
In order to use
LockableCurrency, we need to declare a
LockIdentifier (must be 8 characters long):
Define the lockable currency type:
BalanceOf<T> type satisfies the type constraints of
Self::Balance for all provided
Our pallet must contain the following key functions to ensure it handles the basic logical components for locking and unlocking a currency for a period of time. These are:
fn set_lock: Locks the specified amount of tokens from the caller.
fn extend_lock: Extends the lock period.
fn remove_lock: Releases all locked tokens.
set_lock() method from
extend_lock() method from
remove_lock() method from
Further learning 💡
LockIdentifier. Use this to define logic within the runtime that schedules locking, unlocking, or extends existing locks.
- Composability. Use this basic scheme when writing other pallets that borrow useful methods from mainstream traits.