2.MOVE从入门到实战-编译和运行脚本

  • 木头
  • 更新于 2022-08-09 12:06
  • 阅读 6803

Move 命令行界面(Move CLI)是一种工具,它提供了一种与 Move 交互、测试编写和运行 Move 代码以及测试开发对 Move 开发有用的新工具的简单方法。

开发环境搭建

Move 命令行界面(Move CLI)是一种工具,它提供了一种与 Move 交互、测试编写和运行 Move 代码以及测试开发对 Move 开发有用的新工具的简单方法。

安装

macOS 和 Linux:

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

现在,您应该能够运行Move CLI: image.png 我们将在此处介绍最常见的 Move CLI 命令和标志,但是您可以通过调用 找到可用的命令的完整列表。此外,通过将标志传递给每个 Move CLI 命令,可以找到可用于每个 Move CLI 命令的标志和选项的完整列表,即 move --help --help move <command> --help

新建项目

创建一个新项目的命令:move new

move new <package_name> # Create a Move package <package_name> under the current dir
move new <package_name> -p <path> # Create a Move package <package_name> under path <path>

项目结构

my-move
├─ Move.toml 
└─ sources 

Move.toml

官方配置清单

[package]
name = <string>                  # e.g., "MoveStdlib"
version = "<uint>.<uint>.<uint>" # e.g., "0.1.1"
license* = <string>              # e.g., "MIT", "GPL", "Apache 2.0"
authors* = [<string>]            # e.g., ["Joe Smith (joesmith@noemail.com)", "Jane Smith (janesmith@noemail.com)"]

[addresses]  # (Optional section) Declares named addresses in this package and instantiates named addresses in the package graph
# One or more lines declaring named addresses in the following format
<addr_name> = "_" | "<hex_address>" # e.g., Std = "_" or Addr = "0xC0FFEECAFE"

[dependencies] # (Optional section) Paths to dependencies and instantiations or renamings of named addresses from each dependency
# One or more lines declaring dependencies in the following format
<string> = { local = <string>, addr_subst* = { (<string> = (<string> | "<hex_address>"))+ } } # local dependencies
<string> = { git = <URL ending in .git>, subdir=<path to dir containing Move.toml inside git repo>, rev=<git commit hash>, addr_subst* = { (<string> = (<string> | "<hex_address>"))+ } } # git dependencies

[dev-addresses] # (Optional section) Same as [addresses] section, but only included in "dev" and "test" modes
# One or more lines declaring dev named addresses in the following format
<addr_name> = "_" | "<hex_address>" # e.g., Std = "_" or Addr = "0xC0FFEECAFE"

[dev-dependencies] # (Optional section) Same as [dependencies] section, but only included in "dev" and "test" modes
# One or more lines declaring dev dependencies in the following format
<string> = { local = <string>, addr_subst* = { (<string> = (<string> | <address>))+ } }

项目信息

[package]
name = "my-move"
version = "0.0.0"

Move标准库地址

[dependencies]
MoveStdlib = { git = "https://github.com/move-language/move.git", subdir = "language/move-stdlib", rev = "main" }

模块命名(方便项目直接引用)

[addresses]
std =  "0x1"

编写第一个脚本

由于生成项目默认给的Move标准库是Git地址很慢,可以从https://github.com/diem/diem/tree/latest/language/move-stdlib下载Move的标准库放到本地。 大家也可以使用aptos项目整理好的库https://github.com/aptos-labs/aptos-core/tree/main/aptos-move/framework,下载aptos-stdlib,move-stdlib两个包放在项目同目录

修改项目默认标准库地址

[package]
name = "my-move"
version = "0.0.0"

[addresses]
std = "0x1"

[dependencies]
AptosStdlib = { local = "../aptos-stdlib" }
MoveStdlib = { local = "../move-stdlib" }

新建脚本

sources目录创建一个名为debug_script.move的文件,并在其中输入以下内容:

// sources/debug_script.move
script {
    use std::debug;
    fun debug_script(account: signer) {
        debug::print(&account)
    }
}

在沙盒环境运行脚本

move sandbox run sources/debug_script.move --signers 0xf
[debug] (&) { 0000000000000000000000000000000F }
点赞 4
收藏 3
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

17 条评论

请先 登录 后评论
木头
木头
0xC020...10cf
江湖只有他的大名,没有他的介绍。