rustsubstraterust-ink

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


#![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

Solution

  • 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)