error[E0412]: cannot find type `String` in this scope

3.3k Views Asked by At
#![cfg_attr(not(feature = "std"), no_std)]

use ink_lang as ink;

#[ink::contract]

mod XYZ {

    #[ink(storage)]
    pub struct Xyz {
        token_id: u32,
        serial_code: String
    }
    ...
}

Error:

             serial_code: String
   |                      ^^^^^^ not found in this scope
1

There are 1 best solutions below

1
On BEST ANSWER

Based on this - you should use the String type included in ink!

use ink_prelude::string::String;

And include in the correct Cargo.toml file:

[Dependencies]
ink_prelude = { version = "2", git = "github.com/paritytech/ink", tag = "latest-v2", package = "ink_prelude", default-features = false }"

(or whatever version is correct for you)