1

Error message

 fn panic(info: &core::panic::PanicInfo) -> ! {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: the lang item is first defined in crate `std` (which `parity_scale_codec` depends on)
   = note: first definition in `std` loaded from /home/pinetree/PDAO/polkadot/target/ink/treasury/wasm32-unknown-unknown/release/deps/libstd-466d0a37b6ee82d4.rmeta
   = note: second definition in the local crate (`ink_env`)

I want to import my own crate on ink! contract

my own crate(pdao-beacon-chain-common) is composed like this.

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[cfg_attr(
    feature = "polkadot",
    derive(scale::Encode, scale::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "cosmos", derive(schemars::JsonSchema))]
pub enum DeliverableMessage {
    FungibleTokenTransfer(FungibleTokenTransfer),
    NonFungibleTokenTransfer(NonFungibleTokenTransfer),
    Custom(Custom),
}
...
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[cfg_attr(
    feature = "polkadot",
    derive(scale::Encode, scale::Decode, scale_info::TypeInfo)
)]
pub struct FungibleTokenTransfer {
    pub token_id: String,
    pub amount: u128,
    pub receiver_address: String,
    pub contract_sequence: u64,
}

(refer to https://use.ink/faq#what-are-the-scaleencode-and-scaledecode-traits, to import struct, they should inlcude "scale:Encode, scale:Decode")

and It's dependency is like this

[dependencies]
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "2.0.0", features = ["derive"], optional = true }
...
[features]
polkadot = ["scale", "scale-info"]

And, My Contract import that enum or struct,

...
    use pdao_beacon_chain_common::*;
...

And Contract dependency in Cargo.toml,

[dependencies]
ink_prelude = { version = "3", default-features = false }
ink_primitives = { version = "3", default-features = false }
ink_metadata = { version = "3", default-features = false, features = ["derive"], optional = true }
ink_env = { version = "3", default-features = false }
ink_storage = { version = "3", default-features = false }
ink_lang = { version = "3", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"]}
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }

pdao-beacon-chain-common = { path="../../beacon-chain/common", version = "0.1.0", features = ["polkadot"] }
...
[features]
default = ["std"]
std = [
    "ink_prelude/std",
    "ink_metadata/std",
    "ink_env/std",
    "ink_storage/std",
    "ink_primitives/std",
    "scale/std",
    "scale-info/std",
]

It seems that parity-scale-codec has some dependecy problem. But I still don't know how to resolve it.

Do you have any Ideas..?

2
  • The problem occurs when I build a contract $cargo +nightly contract builld
    – pinetree
    Nov 4, 2022 at 4:28
  • 3
    you haven't included pdao-beacon-chain-common/std on std = []
    – Ganesh11
    Nov 4, 2022 at 7:30

1 Answer 1

1

As stated by @Ganesh11 in the comments, you are likely missing pdao-beacon-chain-common/std in your std features.

I'm commenting the answer so that the question doesn't show up unanswered anymore.

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.