I don't understand this syntax

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

used here...

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

pub use pallet::*;

pub mod pallet {
    use frame_support::{
        sp_runtime::traits::{Hash, Zero},
        dispatch::{DispatchResultWithPostInfo, DispatchResult},
        traits::{Currency, ExistenceRequirement, Randomness},
    use frame_system::pallet_prelude::*;
    use sp_io::hashing::blake2_128;
    type BalanceOf<T> =
    <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

    // TODO Part II: Struct for holding Kitty information.

    // TODO Part II: Enum and implementation to handle Gender type in Kitty struct.

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

    /// Configure the pallet by specifying the parameters and types it depends on.
    pub trait Config: frame_system::Config {
        /// Because this pallet emits events, it depends on the runtime's definition of an event.
        type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;

        /// The Currency handler for the Kitties pallet.
        type Currency: Currency<Self::AccountId>;

        // TODO Part II: Specify the custom types for our runtime.


    // Errors.
    pub enum Error<T> {
        // TODO Part III

    #[pallet::generate_deposit(pub(super) fn deposit_event)]
    pub enum Event<T: Config> {
        // TODO Part III

    #[pallet::getter(fn kitty_cnt)]
    /// Keeps track of the number of Kitties in existence.
    pub(super) type KittyCnt<T: Config> = StorageValue<_, u64, ValueQuery>;

    // TODO Part II: Remaining storage items.

    // TODO Part III: Our pallet's genesis configuration.

    impl<T: Config> Pallet<T> {

        // TODO Part III: create_kitty

        // TODO Part III: set_price

        // TODO Part III: transfer

        // TODO Part III: buy_kitty

        // TODO Part III: breed_kitty

    // TODO Parts II: helper function for Kitty struct

    impl<T: Config> Pallet<T> {
        // TODO Part III: helper functions for dispatchable functions

        // TODO: increment_nonce, random_hash, mint, transfer_from


<Type as Trait>::item means accessing the item on Type, disambiguating the fact that it should come from impl Trait for Type. This is useful when a type has several identically-named associated types or functions from different traits, and you want to be sure you get the right one.

1 Like

still don't get it.
the generic type T is accessing the item in it's implementation of the config trait but what about the second as?

It's the same. <T as Config>::Currency itself implements the trait Currency<…> and it has an associated type named AccountId.

1 Like

That one is the same as:

  type ConfigCurrency<T> = <T as Config>::Currency;
  type ConfigAccountId<T> = <T as frame_system::Config>::AccountId>;
  type BalanceOf<T> = <ConfigCurrency<T> as Currency<ConfigAccountId<T>>::Balance;

It's the exact same construct just repeated three times.


https://substrate.stackexchange.com/ is a good place also for these questions.

Thank you

See also Paths - The Rust Reference (Qualified Paths).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.