0

I am building an ocw demo, the code is from https://github.com/paritytech/substrate/blob/master/frame/examples/offchain-worker/src/lib.rs, when using polkadot-v0.9.25 version, it appears got this error: cannot find trait TryFrom in this scope, I'm sure this code work with polkadot-v0.9.18. enter image description here

Have read this question: Problems With `app_crypto!` Macro, but it didn't solve my problem, this question is so confusing why not found and where this error is triggered

pub mod crypto {
    use super::KEY_TYPE;
    use sp_core::sr25519::Signature as Sr25519Signature;
    use sp_runtime::{
        app_crypto::{app_crypto, sr25519},
        traits::Verify,
        MultiSignature, MultiSigner,
    };
    app_crypto!(sr25519, KEY_TYPE);

    pub struct TestAuthId;

    impl frame_system::offchain::AppCrypto<MultiSigner, MultiSignature> for TestAuthId {
        type RuntimeAppPublic = Public;
        type GenericSignature = sp_core::sr25519::Signature;
        type GenericPublic = sp_core::sr25519::Public;
    }

    // implemented for mock runtime in test
    impl frame_system::offchain::AppCrypto<<Sr25519Signature as Verify>::Signer, Sr25519Signature>
        for TestAuthId
    {
        type RuntimeAppPublic = Public;
        type GenericSignature = sp_core::sr25519::Signature;
        type GenericPublic = sp_core::sr25519::Public;
    }
}

Cargo.toml

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

[dependencies]
lite-json = { version = "0.1", default-features = false }
log = { version = "0.4.17", default-features = false }
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",
] }


# Substrate packages
frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25", optional = true }
frame-support      = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" }
frame-system       = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" }
sp-std             = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" }
sp-keystore             = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25", optional = true}
sp-core = { default-features = false, version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" }
sp-io = { default-features = false, version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" }
sp-runtime = { default-features = false, version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.25" }


[features]
default = ["std"]
std = [
    "codec/std",
    "frame-support/std",
    "frame-system/std",
    "lite-json/std",
    "log/std",
    "scale-info/std",
    "sp-core/std",
    "sp-io/std",
    "sp-keystore",
    "sp-runtime/std",
    "sp-std/std",
]
try-runtime = ["frame-support/try-runtime"]

have tried cargo clean, cargo update,

rustup update
rustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
2
  • What is the command you are running to run into this error?
    – Shawn Tabrizi
    Jul 10, 2022 at 13:06
  • @ShawnTabrizi cargo build --release
    – Bart Yang
    Jul 10, 2022 at 15:15

1 Answer 1

1

Have you tried explicetly importing sp_core::Pair as I've mentioned in the answer you linked above?

1
  • yes. I tried sp_core::Pair, but not work. fix it by add use sp_std::{convert::TryFrom}; to pub mod crypto
    – Bart Yang
    Jul 14, 2022 at 15:40

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.