0
#![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
E_net4
  • 27,810
  • 13
  • 101
  • 139
Aditya Bharti
  • 61
  • 2
  • 5
  • is there a reason why you're explicitly excluding std ? – kalyanswaroop Oct 06 '21 at 14:52
  • String is not part of the Substrate and Ink environments because it increases binary/compiled sizes (likely because of the UTF8 handling). Use `Vec` to store this kind of data if you have to. – apopiak Oct 07 '21 at 09:20

1 Answers1

3

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)

Nuke
  • 1,032
  • 7
  • 13
  • 1
    After including the above, include "ink_prelude = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_prelude", default-features = false }" in the [dependencies] of Cargo.toml file. – Aditya Bharti Oct 06 '21 at 17:57