i wanna to create pallet in substrate . i faced this error . how can i solve this problem ?

#![cfg_attr(not(feature = "std"), no_std)]

/// Edit this file to define custom logic or remove it if it is not needed.
/// Learn more about FRAME and the core library of Substrate FRAME pallets:
/// <https://docs.substrate.io/reference/frame-pallets/>
use codec::alloc::vec;
use frame_support::{
    pallet_prelude::{ValueQuery, *},
        traits::{AccountIdConversion, AtLeast32BitUnsigned, CheckedAdd, Hash, Member, One},
        DispatchError, SaturatedConversion,
    traits::{ExistenceRequirement, Get, ReservableCurrency},
    transactional, PalletId, Twox64Concat,
use frame_system::Config as SystemConfig;
pub use pallet::*;
use sp_runtime::traits::UniqueSaturatedFrom;

mod mock;

mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

mod functions;
mod structs;
mod types;

use structs::labels::Labels::RegisterInputLabelInfo;
use types::types::Types::{
    AccountOf, ArtistInfo, ArtistInfoDetail, BalanceOf, HashId, LabelsDetail,

pub mod pallet {

    use super::*;

    use frame_support::pallet_prelude::*;
    use frame_system::pallet_prelude::*;

    #[pallet::generate_store(pub(super) trait Store)]
    pub struct Pallet<T>(_);

    /// Configure the pallet by specifying the parameters and types on which it depends.
    pub trait Config: frame_system::Config {
        type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
        type Currency: ReservableCurrency<Self::AccountId>;

        type StackLimit: Get<u32>;

        type PalletId: Get<PalletId>;

    #[pallet::getter(fn something)]
    pub type Something<T> = StorageValue<_, u32>;

    #[pallet::getter(fn labels)]
    pub(super) type Labels<T: Config> = StorageDoubleMap<

    // Pallets use events to inform users when important changes are made.
    // https://docs.substrate.io/main-docs/build/events-errors/
    #[pallet::generate_deposit(pub(super) fn deposit_event)]
    pub enum Event<T: Config> {
        /// Event documentation should end with an array that provides descriptive names for event
        /// parameters. [something, who]
        SomethingStored { something: u32, who: T::AccountId },

    // Errors inform users that something went wrong.
    pub enum Error<T> {
        /// Error names should be descriptive.
        /// Errors should have helpful documentation associated with them.

    impl<T: Config> Pallet<T> {
        #[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())]
        pub fn register_labels(
            origin: OriginFor<T>,
            info: RegisterInputLabelInfo,
        ) -> DispatchResult {
            let owner = ensure_signed(origin)?;
            let label_id: HashId<T> = T::Hashing::hash_of(&info.label_name);

        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1).ref_time())]
        pub fn cause_error(origin: OriginFor<T>) -> DispatchResult {
            let _who = ensure_signed(origin)?;

            // Read a value from storage.
            match <Something<T>>::get() {
                // Return an error if the value has not been set.
                None => return Err(Error::<T>::NoneValue.into()),
                Some(old) => {
                    let new = old.checked_add(1).ok_or(Error::<T>::StorageOverflow)?;

Types.rs :

use super::*;

pub mod Types {

    pub use crate::{
            labels::Labels::{LabelInfo, OperationalContact},
    use frame_support::traits::Currency;
    use frame_system::Config as SystemConfig;

    pub type BalanceOf<T> =
        <<T as Config>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;

    pub type HashId<T> = <T as frame_system::Config>::Hash;

    pub type AccountOf<T> = <T as frame_system::Config>::AccountId;

    pub type LabelsDetail<T> = LabelInfo<T>;

    pub type ArtistInfoDetail<T> = ArtistInfo<AccountOf<T>>;


use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{inherent::Vec, traits::ConstU32, BoundedVec};
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;

pub mod Labels {
    use super::*;

    #[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
    pub struct LabelInfo<T: crate::Config> {
        pub owner: T::AccountId,
        pub label_id: T::Hashing,
        pub label_name: BoundedVec<u8, ConstU32<128>>,

i faced this error and i dont know how can i sovle this problem .

error[E0277]: the trait bound LabelInfo<T>: parity_scale_codec::Decode is not satisfied --> /root/Pikamo_Chain/frame/lib.rs:72:15 | 72 | #[pallet::storage]
| ^^^^^^^ the trait parity_scale_codec::Decode is not implemented for LabelInfo<T>

| ^^^^^^^ the trait parity_scale_codec::Decode is not implemented for LabelInfo<T>


1 Answer 1


In stead of providing a generic T: Config to your struct you can also provide generics for your fields:

#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct LabelInfo<AccountId, Hashing> {
    pub owner: AccountId,
    pub label_id: Hashing,
    pub label_name: BoundedVec<u8, ConstU32<128>>,

My reasoning: when bounding your generic argument to your pallet's Config trait, rust macros want this Config to have all those traits implemented.

Now you are not using the pallet's Config in any way and declaring the fields of the struct as generic. In your pallet's code you will define those fields with Config::AccountId which implements those necessary traits.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.