3

Im running through the Substrate Tutorials and just started the Build Application Logic tutorial series. This series starts with implementing pallet_nicks which appears to have been discarded with the transition to Polkadot-SDK. Is that correct? Is there a suitable simple replacement?

I've attempted to instead add pallet_identity but figuring out what to input for the Required Associated Types seems to be a little beyond my scope and skills at this point.

3 Answers 3

1

Current answer

For those who are also stuck on the Build Application Logic tutorial, I found a workaround. There is an old repo that contains the pallet-nicks source code: Nicks pallet

  1. You can simply copy the source code to /note-template/pallets/nicks/;
  2. In ./nicks/Cargo.toml, change the declarations that use local paths to git paths:
    [dependencies]
    ...
    frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
    ...
    
    [dev-dependencies]
    ...
    pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
    ...
  1. In ./runtime/Cargo.toml, add to dependencies:
pallet-nicks = { path = "../pallets/nicks", default-features = false }

and "pallet-nicks/std" to the list of features; 4. In the project root Cargo.toml, add pallets/nicks to the list of members:

[workspace]
members = [
    "node",
    "pallets/template",
    "runtime",
    "pallets/nicks",
]

At least Add a pallet to the runtime environment I was able to do.

Old answer

Please try this declaration:

pallet-nicks = { version = "28.0.0", default-features = false }

I think you got an error during cargo add because you already added the declaration as the manual says. I received:

pallet-nicks = "28.0.0"

via cargo add and just added the feature flag.

5
  • Your suggested declaration worked. Just as a point of understanding, if I leave out the repository tag, does Cargo search crates.io and pull the pallet from there?
    – CODY
    Commented May 20 at 19:26
  • Now that I have the pallet successfully imported I am getting some new errors. impl pallet_nicks::Config for Runtime is generating this error error[E0152]: duplicate lang item in crate `sp_io` (which `frame_support` depends on): `panic_imp`. I am also getting an error from the runtime macro error[E0433]: failed to resolve: could not find `tt_default_parts_v2` in `pallet_nicks` Did some change break the pallet?
    – CODY
    Commented May 20 at 19:53
  • 1. Yes, the tag refers to specifying a dependency from git. You can see the details here: choice of commit 2. Did you use the exact same declaration (version and flag)? Did you add the pallet-nicks/std features to the list of features? Does the rest of Cargo.toml remain in its original state? Because everything is working fine for me. I don't have any errors
    – pcfaktor
    Commented May 21 at 8:41
  • So, I got the same error and don't know how to fix it yet
    – pcfaktor
    Commented May 21 at 15:44
  • Thanks for the update. I was just bashing my head against a wall, but I'll stop that now ;) With my limited knowledge and technical experience, the only idea that I can come up with is there was an update that broke the pallet (does that happen often? seems like there's increasing discussion about update frequency and breaking changes for parachains)
    – CODY
    Commented May 21 at 17:12
1

The nicks pallet still on crates.io, so you can still add it from there.
But if you want some simple pallet to copy the source code into your project, then the best ones to use are:

  • pallet-minimal-template: This pallet does literally nothing. Should be easy to integrate, but also quite boring.
  • pallet-example-basic: This one is quite fat, since it tries to explain all parts of a pallet in detail. You can see how to set its associated config types in the test.rs.

You can also use the pallet-identity, but indeed it requires to set all these config types. There is always the possibility to have a look at the test.rs files of these pallets to find some mocked configuration.

1
  • I tried to install nicks from crates.io using the provided command: Cargo add pallet-nicks and received an error message stating error: the crate `pallet-nicks@https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0` could not be found in registry index. I get a similar error (error: no matching package found) when I try adding it to the dependencies in Cargo.toml I did find the source code at link but Im not sure how to download that source code. test.rs is extremely helpful. Thanks for that tip
    – CODY
    Commented May 16 at 20:58
0

It seems you missed some configuration when adding the pallet. You can do it in the following way:

  1. Start with the substrate node template version 1.9.0, (im fixing the commit in the command):

    git clone [email protected]:substrate-developer-hub/substrate-node-template.git --branch main --single-branch --depth 1 --no-checkout && \
    cd substrate-node-template && \
    git checkout d70f8f9793cdd869571c21d7253faa50baaa5c5b
    
  2. Make sure it compiles:

    cargo build --release
    
  3. Copy nicks pallet source code to /note-template/pallets/nicks/

  4. In ./nicks/Cargo.toml, change the declarations that use local paths to git paths:

    #...
    [dependencies]
    codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] }
    scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
    frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
    frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
    sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
    sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
    sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
    
    [dev-dependencies]
    pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0" }
    sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0" }
    #...
    
  5. In ./runtime/Cargo.toml, add to dependencies:

    # The pallet in this template.
    pallet-template = { path = "../pallets/template", default-features = false }
    # Adding nicks pallet.
    pallet-nicks = { path = "../pallets/nicks", default-features = false }
    

    and "pallet-nicks/std" to the list of features;

    std = [
    #...
    "pallet-template/std",
    "pallet-nicks/std",
    #...
    ]
    
  6. In the project root ./Cargo.toml, add pallets/nicks to the list of members:

    [workspace]
    members = [
    "node",
    "pallets/template",
    "pallets/nicks",
    "runtime",
    ]
    
  7. Check all ok until this stage:

    cargo check -p node-template-runtime --release
    
  8. Implement the configuration for Nicks insisde the ./runtime/src/lib.rs

    • Add it to mod runtime:
    #[frame_support::runtime]
    mod runtime {
        ...
    
        // Include the custom logic from the pallet-template in the runtime.
        #[runtime::pallet_index(7)]
        pub type TemplateModule = pallet_template;
    
        // Add nicks pallet
        #[runtime::pallet_index(8)]
        pub type NicksModule = pallet_nicks;
    }
    
    • And also include the pallet config implementation:
    /// Configure the pallet-template in pallets/template.
    impl pallet_template::Config for Runtime {
        type RuntimeEvent = RuntimeEvent;
        type WeightInfo = pallet_template::weights::SubstrateWeight<Runtime>;
    }
    
    /// Configure the pallet-nicks
    impl pallet_nicks::Config for Runtime {
        // The Balances pallet implements the ReservableCurrency trait.
        // `Balances` is defined in `construct_runtime!` macro.
        type Currency = Balances;
    
        // Set ReservationFee to a value.
        type ReservationFee = ConstU128<100>;
    
        // No action is taken when deposits are forfeited.
        type Slashed = ();
    
        // Configure the FRAME System Root origin as the Nick pallet admin.
        // https://paritytech.github.io/substrate/master/frame_system/enum.RawOrigin.html#variant.Root
        type ForceOrigin = frame_system::EnsureRoot<AccountId>;
    
        // Set MinLength of nick name to a desired value.
        type MinLength = ConstU32<8>;
    
        // Set MaxLength of nick name to a desired value.
        type MaxLength = ConstU32<32>;
    
        // The ubiquitous event type.
        type RuntimeEvent = RuntimeEvent;
    }
    
  9. Compile:

    cargo build --release
    
  10. Run it in dev mode for testing:

    ./target/release/node-template --dev
    

If you get lost, you can find the code which I tested here.

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.