3

I am trying to add a custom rpc in Substrate, but I ran into a problem.

I have done all steps in this article:

Add custom RPC to the node

and my code is here:

https://github.com/dortajkianoush/substrate_rpc

but it shows me this error:

error: 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 `frame_support` depends on)
    = note: first definition in `sp_io` loaded from /home/kianoush/projects/substrate_rpc/target/debug/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-ff5bbb618e892e0d.rmeta
    = note: second definition in `sp_io` loaded from /home/kianoush/projects/substrate_rpc/target/debug/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-c5af71db43952901.rmeta

  error: duplicate lang item in crate `sp_io` (which `sp_application_crypto` depends on): `oom`.
    |
    = note: the lang item is first defined in crate `sp_io` (which `frame_support` depends on)
    = note: first definition in `sp_io` loaded from /home/kianoush/projects/substrate_rpc/target/debug/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-ff5bbb618e892e0d.rmeta
    = note: second definition in `sp_io` loaded from /home/kianoush/projects/substrate_rpc/target/debug/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-c5af71db43952901.rmeta

  error[E0277]: the trait bound `sp_runtime::generic::Block<sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>, sp_runtime::generic::UncheckedExtrinsic<MultiAddress<AccountId32, ()>, RuntimeCall, MultiSignature, (CheckNonZeroSender<Runtime>, CheckSpecVersion<Runtime>, CheckTxVersion<Runtime>, CheckGenesis<Runtime>, CheckEra<Runtime>, CheckNonce<Runtime>, CheckWeight<Runtime>, ChargeTransactionPayment<Runtime>)>>: sp_runtime::traits::Block` is not satisfied
     --> /home/kianoush/projects/substrate_rpc/runtime/src/lib.rs:403:7
      |
  403 |     impl pallet_template_runtime_api::TemplateApi<Block> for Runtime {
      |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `sp_runtime::traits::Block` is not implemented for `sp_runtime::generic::Block<sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>, sp_runtime::generic::UncheckedExtrinsic<MultiAddress<AccountId32, ()>, RuntimeCall, MultiSignature, (CheckNonZeroSender<Runtime>, CheckSpecVersion<Runtime>, CheckTxVersion<Runtime>, CheckGenesis<Runtime>, CheckEra<Runtime>, CheckNonce<Runtime>, CheckWeight<Runtime>, ChargeTransactionPayment<Runtime>)>>`
      |
      = help: the trait `sp_runtime::traits::Block` is implemented for `sp_runtime::generic::block::Block<Header, Extrinsic>`
  note: required by a bound in `TemplateApi`
     --> /home/kianoush/projects/substrate_rpc/pallets/template/rpc/runtime-api/src/lib.rs:5:1
      |
  5   | / sp_api::decl_runtime_apis! {
  6   | |     pub trait TemplateApi {
  7   | |         fn get_value() -> u32;
  8   | |     }
  9   | | }
      | |_^ required by this bound in `TemplateApi`
      = note: this error originates in the macro `sp_api::decl_runtime_apis` (in Nightly builds, run with -Z macro-backtrace for more info)

  For more information about this error, try `rustc --explain E0277`.
  error: could not compile `node-template-runtime` due to 3 previous errors

1 Answer 1

2

This error appears when you mismatch the version of Substrate you are using across your project.

See previous answers on this forum like: How to resolve duplicate lang item error?

For example, in your project, you see that everything is using branch = "polkadot-v0.9.35", but the tutorial says to copy branch = "polkadot-v0.9.28", so you should make sure when you are copying from the tutorial, to change the branch to match the rest of your project.

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.