5

I'm trying to make some changes to the Flipper contract, trying to use a vector like the documentation say's it should be imported:

#[ink::contract]
pub mod flipper_plus {
    use ink::storage::Mapping;
    use ink::prelude::vec::Vec;

and during compilation got this errors:

error[E0432]: unresolved import `crate::flipper_plus::vec`
 --> /Users/pierina/Documents/rust_projects/flipper-contract/contracts/flipperPlus/src/lib.rs:7:30
  |
7 |     use crate::flipper_plus::vec::Vec;
  |                              ^^^ could not find `vec` in `flipper_plus`

error: cannot find macro `vec` in this scope
  --> /Users/pierina/Documents/rust_projects/flipper-contract/contracts/flipperPlus/src/lib.rs:33:26
   |
33 |                 history: vec![(caller, init_value, Self::env().block_timestamp())], 
   |                          ^^^

Here is my Cargo.toml:

[package]
name = "flipper_plus"
version = "0.1.0"
authors = [""]
edition = "2021"

[dependencies]
ink = { version = "4.0.0", default-features = false }

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

[lib]
name = "flipper_plus"
path = "src/lib.rs"
crate-type = [
    # Used for normal contract Wasm blobs.
    "cdylib",
]

[features]
default = ["std"]
std = [
    "ink/std",
    "scale/std",
    "scale-info/std"
]
ink-as-dependency = []

1
  • import in this way @Pierina Ponce use ink::prelude::{ vec, vec::Vec }
    – go11li
    Commented Apr 18, 2023 at 1:28

2 Answers 2

4

You only imported Vec. So, it could not find vec!.

And this error use crate::flipper_plus::vec::Vec;. It isn't the same as the code that you provided. use ink::prelude::vec::Vec;.

So, please update those imports correctly.

https://docs.rs/ink_prelude/4.1.0/ink_prelude/index.html

use ink::prelude::{vec, vec::Vec};
0

You need firstly add to your Cargo.toml following line:

ink_prelude = { version = "4.0.2", default-features = false }

and then you can use vec like:

use ink::prelude::{vec, vec::Vec};

Documentation: https://crates.io/crates/ink_prelude

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.