筆記 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