基本类型

Move 的基本数据类型包括: 整型 (u8, u32,u64, u128,u258)、布尔型 boolean 和地址 address。

Move 不支持字符串和浮点数。

module ch02::int {
    fun main() {
        // define empty variable, set value later
        let a: u8;
        a = 10;

        let a = 1u32;

        // define variable, set type
        let a: u64 = 10;

        // finally simple assignment
        let a = 10;

        // simple assignment with defined value type
        let a = 10u64;

        // in function calls or expressions you can use ints as constant values
        if (a < 10) {};

        // or like this, with type
        if (a < 10u64) {}; // usually you don't need to specify type

        let b = 1u256;

        // or like this, with type
        if (b < 10u256) {}; // usually you don't need to specify type
    }
}


let a = 10 默认不手动标记类型的整型是 u64 类型,也就是等同于 let a:u64 = 10 或者 let a = 10u64

布尔型

布尔类型就像编程语言那样,包含false和true两个值。

module book::boolean {
    fun main() {
        // these are all the ways to do it
        let b : bool; b = true;
        let b : bool = true;
        let b = true;
        let b = false; // here's an example with false
    }
}

地址

地址是区块链中交易发送者的标识符,转账和导入模块这些基本操作都离不开地址。

module book::addr {
    fun main() {
        let addr: address; // type identifier

        addr = @ch02;
    }
}