错误 [E0412]:在此范围内找不到类型 `String`

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
    }
    ...
}

错误:

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

基于 - 您应该使用包含在 ink!

中的 String 类型
use ink_prelude::string::String;

并包含在正确的 Cargo.toml 文件中:

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

(或任何适合您的版本)