1

I'm developing a project based on the substrate-node-template and encountered an issue when adding a subxt dependency. When I add subxt = { version = "0.29", default-features = false } to the Cargo.toml of the node-template module, everything works fine. Here is a part of the Cargo.toml from the node-template module:

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

[[bin]]
name = "node-template"

[dependencies]
subxt = { version = "0.29", default-features = false }

[build-dependencies]
substrate-build-script-utils.workspace = true

[features]
default = []

However, adding the same dependency to the node-template-runtime module's Cargo.toml leads to an error. Here is a part of the Cargo.toml from the node-template-runtime module:

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

[dependencies]
subxt = { version = "0.29", default-features = false }

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

[features]
default = ["std"]

The error message I receive is:

error[E0152]: found duplicate lang item `panic_impl`
note: the lang item is first defined in crate `std` (which `tracing` depends on)
note: second definition in the local crate (`sp_io`)
error: could not compile `sp-io` (lib) due to 1 previous error

I have two questions:

  1. Why does adding this dependency to the node-template-runtime module cause an error?
  2. I've heard that all dependencies in node-template-runtime must be no_std, but why then does the Cargo.toml of the node-template-runtime module have default = ["std"] in its features?

Any insights or suggestions would be greatly appreciated.

2 Answers 2

2

Why does adding this dependency to the node-template-runtime module cause an error?

The runtime must support compiling the code to no-std and subxt doesn't support that yet. There are ongoing work to make parts of subxt to be no-std though. That's why you get the error found duplicate lang item panic_impl`

I've heard that all dependencies in node-template-runtime must be no_std, but why then does the Cargo.toml of the node-template-runtime module have default = ["std"] in its features?

The std feature is only enabled when the runtime is compiled to native and that's those std features exist.

1

You should not add subxt to your chain build, subxt is designed to connect to your chain using rpc. Create a tool to submit extrinsics and read state from the chain like polkadot-js does but from rust code.

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.