1

I am following the Substrate tutorial on adding pallets. However, when I add pallet-nicks to the Cargo.toml located in the runtime folder and then add the pallets-nicks implementation to the lib.rs file in runtime/src, I get the following error:

error[E0152]: duplicate lang item in crate `sp_io` (which `frame_support` depends on): `panic_impl`.
    |
    = note: the lang item is first defined in crate `sp_io` (which `frame_support` depends on)
    = note: first definition in `sp_io` loaded from /code/substrate-node-template/target/release/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-28bcc0f1aaf2e4a2.rmeta
    = note: second definition in `sp_io` loaded from /code/substrate-node-template/target/release/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-151d2b924b052e86.rmeta

This is my Cargo.toml file:

[package]
name = "node-template-runtime"
version = "4.0.0-dev"
description = "A fresh FRAME-based Substrate node, ready for hacking."
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>"]
homepage = "https://substrate.io/"
edition = "2021"
license = "Unlicense"
publish = false
repository = "https://github.com/substrate-developer-hub/substrate-node-template/"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }

pallet-aura = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", optional = true , " branch" = "polkadot-v0.9.35" }
pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
sp-block-builder = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
sp-consensus-aura = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
sp-core = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
sp-runtime = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
sp-std = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
sp-version = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
Added this line -> pallet-nicks = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.35" }

# Used for the node template's RPCs
frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }
pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }

# Used for runtime benchmarking
frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", optional = true , " branch" = "polkadot-v0.9.35" }
frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", optional = true , " branch" = "polkadot-v0.9.35" }

# Local Dependencies
pallet-template = { version = "4.0.0-dev", default-features = false, path = "../pallets/template" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", " branch" = "polkadot-v0.9.35" }

[features]
default = ["std"]
std = [
    "frame-try-runtime?/std",
    "frame-system-benchmarking?/std",
    "frame-benchmarking?/std",
    "codec/std",
    "scale-info/std",
    "frame-executive/std",
    "frame-support/std",
    "frame-system-rpc-runtime-api/std",
    "frame-system/std",
    "frame-try-runtime/std",
    "pallet-aura/std",
    "pallet-balances/std",
    "pallet-grandpa/std",
    "pallet-randomness-collective-flip/std",
    "pallet-sudo/std",
    "pallet-template/std",
    "pallet-timestamp/std",
    "pallet-transaction-payment-rpc-runtime-api/std",
    "pallet-transaction-payment/std",
    "sp-api/std",
    "sp-block-builder/std",
    "sp-consensus-aura/std",
    "sp-core/std",
    "sp-inherents/std",
    "sp-offchain/std",
    "sp-runtime/std",
    "sp-session/std",
    "sp-std/std",
    "sp-transaction-pool/std",
    "sp-version/std",
    Added this line -> "pallet-nicks/std",
]
runtime-benchmarks = [
    "frame-benchmarking/runtime-benchmarks",
    "frame-support/runtime-benchmarks",
    "frame-system-benchmarking/runtime-benchmarks",
    "frame-system/runtime-benchmarks",
    "pallet-balances/runtime-benchmarks",
    "pallet-grandpa/runtime-benchmarks",
    "pallet-template/runtime-benchmarks",
    "pallet-timestamp/runtime-benchmarks",
    "sp-runtime/runtime-benchmarks",
]
try-runtime = [
    "frame-try-runtime/try-runtime",
    "frame-executive/try-runtime",
    "frame-system/try-runtime",
    "frame-support/try-runtime",
    "pallet-aura/try-runtime",
    "pallet-balances/try-runtime",
    "pallet-grandpa/try-runtime",
    "pallet-randomness-collective-flip/try-runtime",
    "pallet-sudo/try-runtime",
    "pallet-template/try-runtime",
    "pallet-timestamp/try-runtime",
    "pallet-transaction-payment/try-runtime",
]

This is the implementation that I added to the lib.rs file in runtime/src/:

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;
}

// Also added the pallet to the construct_runtime macro:
construct_runtime!(
    pub struct Runtime
    where
        Block = Block,
        NodeBlock = opaque::Block,
        UncheckedExtrinsic = UncheckedExtrinsic,
    {
        System: frame_system,
        RandomnessCollectiveFlip: pallet_randomness_collective_flip,
        Timestamp: pallet_timestamp,
        Aura: pallet_aura,
        Grandpa: pallet_grandpa,
        Balances: pallet_balances,
    Nicks: pallet_nicks,
        TransactionPayment: pallet_transaction_payment,
        Sudo: pallet_sudo,
        // Include the custom logic from the pallet-template in the runtime.
        TemplateModule: pallet_template,
    }
);

If I comment out the implementation from the lib.rs and the construct_runtime macro, I can build successfully. I am very new to Rust and Substrate. Any ideas on how I can go about fixing this? I've seen questions with similar errors but I've been unable to resolve this error.

This is the result of running rustup show. I am running all of this on WSL on Windows:

Default host: x86_64-unknown-linux-gnu
rustup home:  /root/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.65.0 (897e37553 2022-11-02)
5
  • This error is just when you add the nicks pallet? or without the nick pallet you have it too
    – Alex Bean
    Dec 15, 2022 at 14:59
  • Only upon adding the nicks pallet.
    – chomprrr
    Dec 15, 2022 at 15:01
  • Does this answer your question? How to resolve duplicate lang item error? Dec 15, 2022 at 16:54
  • I have tried the suggestions solutions but could not resolve the error. In my case, the error goes away if I comment out the code related to the nicks pallet from the lib.rs file.
    – chomprrr
    Dec 15, 2022 at 17:47
  • I was able to resolve this error by using version: polkadot-v0.9.31 instead of polkadot-v0.9.35
    – chomprrr
    Dec 16, 2022 at 6:54

1 Answer 1

1

There seems to be an issue with the substrate-node-template, I have seen this PR that fixes it: remove space from manifest key branch in all the cargo.toml files

In the meantime is approved if you want to try it locally just replace in all files (Cargo.toml files) " branch" with "branch" (removing the space)

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.