Move 快速入门 之 Move 环境安装

Move 环境安装

move语言是一种面向区块链资产的编程语言, 是一种解释性语言,由MoveVM(使用rust开发)解释执行

安装Rust环境

  1. 安装rust开发工具链
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. 设置系统path(ps: 由于我的是mac, 直接在 ~/.zprofile 配置就行)
echo "export PATH=$PATH:~/.cargo/bin" >> ~/.zprofile

安装Move

安装move-cli

move-cli 是用rust开发的工具, 集成了MoveVM、move编译器.

直接从git编译安装:

cargo install --debug --git https://github.com/move-language/move move-cli --branch main

或者先拉取源码再编译:

git clone git https://github.com/move-language/move.git
cargo install --debug --path move/language/tools/move-cli

完成后 move 二进制文件存在 ~/.cargo/bin 目录中,所以要确保这个目录在系统path中.

检查move是否安装成功, 终端中执行 move 即可:

move

安装成功的话, 会出现如下图所示内容:

image-20220830225912791

安装move-prover所需工具

prove 是move-cli 中的一个字命令, 用于对合约进行形式化验证分析.

git clone git https://github.com/move-language/move.git
cd move
./scripts/dev_setup.sh -yp
. ~/.profile

正常来说,会生成一个 ~/.profile 文件, 为了方便, 可以把profile 内容放到 ~/.zprofile 或者 ~/.bash-profile中.

第一个move程序

使用move new 创建一个helloworld程序

move new helloworld

默认情况下move 会创一个Move.toml 管理文件 和 一个sources 文件夹, move 代码存在sources文件夹下

.
├── Move.toml
└── sources

1 directory, 1 file

让我们在sources下创建一个helloworld.move,内容如下:

// sources/helloworld.move
script {
use std::debug;
fun hello(){
    let str = b"hello move";
    debug::print(&str);
}
}

由于代码中使用了print, 我们需要引入标准库, 修改Move.toml, 添加dependencies:

[package]
name = "helloworld"
version = "0.0.0"

[dependencies]
MoveNursery = { git = "https://github.com/move-language/move.git", subdir = "language/move-stdlib/nursery", rev = "main" }
[addresses]
std =  "0x1"

让我们运行它看看:

move sandbox run sources/helloworld.move

程序会输出如下内容:

image-20220831194340813

debug::print 是无法输出字符,因此这里打印了 对应的ascii 码值.

References

https://github.com/move-language/move/tree/main/language/move-prover

https://github.com/move-language/move/tree/main/language/tools/move-cli