500-move基础
0x-wen

move基础课

Task1

环境安装

任务概览

  1. fork这个仓库 letsmove
  2. 复制 mover/001 并重命名为自己github名称,例子:

image

  1. 查看task1的任务列表 task1的任务明细 , 交作业的参考文章
  2. 在项目letsmove/mover/0x-wen 目录下更新readme.md
  3. 在readme.md 中需要填写sui地址,建议使用sui插件钱包中地址,或者okx中sui地址
  4. letsmove/mover/0x-wen路径下创建 images文件夹,并上传两个图片,分别为钱包截图和浏览器搜索截图
  5. 完成后提交本地代码,同步远程最新代码后,全部操作完成后提交PR

操作步骤

  1. 完成Sui CLI安装, 根据官方文档安装

    1
    2
    3
    4
    5
    # 安装完成后先生成一个地址
    # 查看,首次则一直回车,如果提示加密方式就选择 0
    sui client addresses
    # 创建 {ed25519 | secp256k1 | secp256r1} 不同的加密方式
    sui client new-address ed25519
  2. 完成获取测试网络SUI学习,主要是领取测试网代币

    1
    2
    3
    4
    5
    6
    7
    curl --location --request POST 'https://faucet.testnet.sui.io/gas' \
    --header 'Content-Type: application/json' \
    --data-raw '{
    "FixedAmountRequest": {
    "recipient": "替换成本地地址"
    }
    }'
  3. Hello Move 合约必须包含自己github id 输出内容是 github id

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # 切换到项目路径:letsmove/mover/0x-wen/code 
    # 创建一个项目
    sui move new hello

    # 项目结构
    $ tree hello
    hello
    ├── Move.toml
    ├── sources
    │   └── hello.move
    └── tests
    └── hello_tests.move
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    // 更改hello.move 代码
    module hello::hello {
    use std::ascii::{String, string};
    use sui::object::{Self,UID};
    use sui::transfer::transfer;
    use sui::tx_context::{TxContext, sender};

    public struct Hello has key{
    id:UID,
    say: String
    }

    fun init(ctx: &mut TxContext) {
    let hello_move = Hello {
    id:object::new(ctx),
    say: string(b"0x-wen"), // 替换github
    };
    transfer(hello_move, sender(ctx));
    }
    }
  4. 执行部署命令

    1
    2
    $ sui move build 
    $ sui client publish # 部署合约
  5. 提交Hello Move合约发布package id

    1
    2
    3
    4
    5
    6
    Published Objects:                                                                         

    PackageID: 0xdecabd09762d6a7ed908127b170ce358f80b2d6b1932cbf0845b8731d1802033
    Version: 1
    Digest: DaUN8sMqky89FvzZvsrJVdVYmGabwkw4KdnkyF1bdXvF
    Modules: hello
  6. 拿着PackageID 去测试网浏览器【注意切换网络】 搜索一下并截图

  7. 提交安装好浏览器钱包的截图到 images 目录下

create-dapp

创建一个可以和合约交互的前端应用

通过手脚架生成项目结构

1
2
3
4
5
6
# 路径: 0x-wen/code/
npm create @mysten/dapp

# 选择 e2e-counter

# 创建一个名称为 hello_dapp

更改相关配置后部署

1
2
3
4
5
6
7
8
9
# 更新默认生成的toml文件
vim 0x-wen/code/hello_dapp/move/counter/Move.toml

# 将依赖分支更改为测试分支
rev = "framework/testnet"

# 执行部署
cd 0x-wen/code/hello_dapp/move/counter
sui client publish

替换部署成功后的package-id

1
2
3
// 0x-wen/code/hello_dapp/src/constants.ts

export const TESTNET_COUNTER_PACKAGE_ID = "0x54fae9c956cc1a2ef3f1436e1fa008a7230d7f79070c58bfc070c5d893315483"; // 替换部署成功后的package

下载依赖并本地启动

1
2
3
4
5
6
7
# 路径:0x-wen/code/hello_dapp
npm install

# 本地启动
npm run dev

# 先在sui-wallet中切换到测试网络,在打开本地页面选择连接wallet,然后使用页面完成交互和发送交易
由 Hexo 驱动 & 主题 Keep
总字数 41.3k