0

I am building a solo chain from Substrate node template, I have made some changes to switch from PoA to PoS just like this repo. Now, I am trying to add pallet-contracts on the runtime. I added the following in the Cargo.toml file:

pallet-contracts = { version = "23.0.0", package = "pallet-contracts", default-features = false }
pallet-contracts-primitives = { version = "27.0.0", package = "pallet-contracts-primitives", default-features = false }


[features]
default = ["std"]
std = [
    ...,
    "pallet-contracts/std",
    "pallet-contracts-primitives/std",

]

Now when I try to implement the Config trait for the Contracts pallet I add the following code:

impl pallet_contracts::Config for Runtime {
    type Time = Timestamp;
    type Randomness = RandomnessCollectiveFlip;
    type Currency = Balances;
    type RuntimeEvent = RuntimeEvent;
    type RuntimeCall = RuntimeCall;
    /// The safest default is to allow no calls at all.
    ///
    /// Runtimes should whitelist dispatchables that are allowed to be called from contracts
    /// and make sure they are stable. Dispatchables exposed to contracts are not allowed to
    /// change because that would break already deployed contracts. The `Call` structure itself
    /// is not allowed to change the indices of existing pallets, too.
    type CallFilter = Nothing;
    type DepositPerItem = DepositPerItem;
    type DepositPerByte = DepositPerByte;
    type DefaultDepositLimit = DefaultDepositLimit;
    type CallStack = [pallet_contracts::Frame<Self>; 5];
    type WeightPrice = pallet_transaction_payment::Pallet<Self>;
    type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
    type ChainExtension = ();
    type Schedule = Schedule;
    type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
    type MaxCodeLen = ConstU32<{ 123 * 1024 }>;
    type MaxStorageKeyLen = ConstU32<128>;
    type UnsafeUnstableInterface = ConstBool<false>;
    type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>;
    type RuntimeHoldReason = RuntimeHoldReason;
    #[cfg(not(feature = "runtime-benchmarks"))]
    type Migrations = ();
    #[cfg(feature = "runtime-benchmarks")]
    type Migrations = pallet_contracts::migration::codegen::BenchMigrations;
    type MaxDelegateDependencies = ConstU32<32>;
    type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
    type Debug = ();
    type Environment = ();
}

But adding this code gave me this error (among others), which I am not sure why it happens:

 error[E0152]: duplicate lang item in crate `sp_io` (which `sp_application_crypto` depends on): `panic_impl`.
    |
    = note: the lang item is first defined in crate `sp_io` (which `node_template_runtime` depends on)
    = note: first definition in `sp_io` loaded from /Users/macbookpro/Desktop/MainGitReposBlockchain/Devolved_AI_Blockchain/NodeMainTemplate/target/release/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-2d4b947295faf0f7.rmeta
    = note: second definition in `sp_io` loaded from /Users/macbookpro/Desktop/MainGitReposBlockchain/Devolved_AI_Blockchain/NodeMainTemplate/target/release/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-6ce5327a26e230a7.rmeta

How do I resolve this error?

1
  • Can you share the whole Cargo.toml? It looks there is some error with the imports
    – Alex Bean
    Oct 23, 2023 at 13:53

1 Answer 1

0

Import pallet-contract in runtime/Cargo.toml ( should be the same branch)

pallet-contracts = {git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", default-features = false }
pallet-contracts-primitives = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", default-features = false }

Remember that you should add std features:

https://github.com/Aideepakchaudhary/proof-of-stake-node-template/blob/main/runtime/Cargo.toml#L76

pallet-contracts/std

pallet-contracts-primitives/std

You can check this reference:

https://github.com/truongngoctan91/add_pallet_contracts/tree/main

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.