笔记 Map: Move on Aptos 春季训练营
环境安装#
1. rust 环境
验证:命令行输入 cargo
2. aptos move 环境
https://aptos.dev/tools/aptos-cli/use-cli/use-aptos-cli
验证:命令行输入 aptos
Windows 环境变量设置
快捷键 win + R,输入 sysdm.cpl 打开 System Properties
选择 Advanced,下方打开 Environment Variables…
创建项目#
- 初始化 move 项目
aptos move init —name lesson1
- 初始化账号
aptos init
项目结构
│ Move.toml// 项目的配置,如项目名称,项目地址,第三方包
├─ .aptos// 模块所指向的账户及项目配置信息
│ config.yaml
├─ scripts // 脚本文件,用来调用模块(用的少)
├─ sources // 模块文件夹,模块和测试可以放在这里面
└─ tests // 测试文件,用来写测试用例(用的少)
Config.yaml#
-
private_key: 账号私钥
-
public_key: 账号公钥
-
account: 账户
-
rest_url: 节点地址
-
faucet_url: 水龙头地址
创建好账号会自动领取测试链上的代币作为手续费
Move.yaml#
-
[package]: 项目信息
-
[addresses]: 地址全局变量
-
[dev-addresses]: 测试地址变量
-
[dependencies.AptosFramework]: 依赖项
-
[dev-dependencies]: 测试依赖性
Helloworld 项目#
sources 文件夹下建立 main.move 文件:
module Lesson1::HelloWorld{
use std::debug::print;
use std::string::utf8; //Move doesn't support String type, you need to introduce string.
#[test]
fun test_hello_world(){
print(&utf8(b"Hello World")); //
/*
1. Strings are not recognized and need to be preceded by a b, meaning converted to bytes.
2. & var, for read-only, & mut var, for readable and writable
*/
}
}
注意事项已写入备注,连备注里都不能写中文字符,否则编译会报错。
保存代码后通过 aptos init
进行编译
通过 aptos move test
进行运行
控制台会输出 Hello World