type
Post
status
Published
date
Feb 14, 2025
slug
summary
Sui 训练营 Task 1 的学习笔记,结合 The Move Book 进行了拓展,增加了对发布包程序后是否成功的验证,和对已发布程序的交互操作,真正能在 CLI 和区块浏览器中看到 Hello World 得到反馈,并补充了 PTB 的小技巧。
tags
Move
category
Web3
icon
password
Property
Feb 17, 2025 07:11 AM
本文目标
- 安装好 Sui 钱包
- 安装好 Sui CLI 工具
- 安装 Sui Move 的编辑器插件
- 将 Hello Move 发布上链
- 了解 Sui 区块浏览器的使用
安装 Sui 钱包
官方钱包
官方出的钱包,个人使用起来感觉还可以,但是很多群友反馈说体验很差…
Nightly
Nightly 钱包感觉更丝滑一些,连 Galxe 很流畅(官方钱包连不上)。
安装 Sui CLI 工具
我的电脑是 Mac ,并且已经安装了 Brew 包管理工具
brew install sui
其他系统用各自的包管理工具安装即可。
教程里还有 Docker 安装的方法,但是我暂时想不到用 Docker 的意义是什么。
检查是否安装成功
sui --version
能正确输出版本号即为成功
sui 1.37.3-homebrew

对于新手来说,
sui console
sui client
sui move
将会是比较常用的几个子命令,其他命令可以暂时忽略,有必要再学习。Sui CLI 官方文档如下:
Sui CLI 官方中文文档如下:
安装 Sui Move 编辑器插件
写代码的时候安装对应语言的编辑器插件可以提升开发体验
我使用的是 VSCode 在插件市场里搜索 Move

安装 Mysten Labs 的那个就好,依赖会自动安装。
如果是 Windows 电脑,貌似还要设置一下 Sui 的路径。Mac 不需要。
安装好编辑器插件,代码就能高亮显示和识别语法错误了。
发布 Hello Move 上链
与所有的编程语言入门文章一样,新手的第一课就是写一个 Hello World。
先创建项目
切换到你想创建项目的目录
sui move new hello_move
项目结构如下:
. └── hello_move ├── Move.toml ├── sources │ └── hello_move.move └── tests └── hello_move_tests.move
Move.toml
文件被称为包清单,它包含包的定义和配置设置。它被Move编译器用来管理包的元数据、获取依赖项和注册命名地址。sources/
目录包含源文件。Move源文件的扩展名是.move
,通常以文件中定义的模块命名。例如,在我们的例子中,文件名是 hello_world.move
,Move CLI 已经在其中放置了注释的代码。tests/
目录包含包测试。编译器在常规构建过程中将排除这些文件,但在测试和开发模式下使用它们。编译代码
用编辑器打开
hello_move.move
将 hello move 的代码复制粘贴进去/// 命名地址 `hello_world` 下的 `hello_world` 模块。 /// 命名地址在 `Move.toml` 中设置。 module hello_world::hello_world { // 从标准库导入 `String` 类型 use std::string::String; /// 返回 "Hello, World!" 作为 `String`。 public fun hello_world(): String { b"Hello, World!".to_string() } }
Move 是一种编译型语言,因此它需要将源文件编译成 Move 字节码。字节码只包含关于模块、其成员和类型的必要信息,同时排除了注释和某些标识符(例如,常量的标识符)。
# 在 `hello_world` 文件夹中运行 sui move build
它应该在你的控制台输出以下消息:
UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git INCLUDING DEPENDENCY Sui INCLUDING DEPENDENCY MoveStdlib BUILDING hello_world
在编译过程中,Move 编译器会自动创建一个 build 文件夹,其中放置所有获取和编译的依赖项,以及当前包的模块的字节码。
运行测试
在开始测试之前,我们应该添加一个测试。Move 编译器支持用 Move 编写的测试,并提供执行环境。测试可以放在源文件中,也可以放在
tests/
文件夹中。测试用 #[test]
属性标记,编译器会自动发现它们。我们将在 测试 部分深入解释测试。请用以下内容替换
tests/hello_world_tests.move
:#[test_only] module hello_world::hello_world_tests { use hello_world::hello_world; #[test] fun test_hello_world() { assert!(hello_world::hello_world() == b"Hello, World!".to_string(), 0); } }
这里我们导入
hello_world
模块,并调用其 hello_world
函数来测试输出是否为字符串 "Hello, World!"。现在我们已经准备好了测试,让我们在测试模式下编译并运行测试。Move CLI 有 test
命令用于此目的:sui move test
将有以下内容输出:
INCLUDING DEPENDENCY Sui INCLUDING DEPENDENCY MoveStdlib BUILDING hello_world Running Move unit tests [ PASS ] 0x0::hello_world_tests::test_hello_world Test result: OK. Total tests: 1; passed: 1; failed: 0
设置账户
为了发布和与包交互,我们需要设置一个账户。
如果你是第一次设置账户,需要运行
sui client
命令,然后 CLI 将提示你回答多个问题。下面是答案示例,以 >
开头:sui client Config file ["/path/to/home/.sui/sui_config/client.yaml"] doesn't exist, do you want to connect to a Sui Full node server [y/N]? > y Sui Full node server URL (Defaults to Sui Testnet if not specified) : > Select key scheme to generate keypair (0 for ed25519, 1 for secp256k1, 2: for secp256r1): > 0
回答完问题后,CLI 将生成一个新的密钥对并保存到配置文件中。现在你可以使用这个账户与网络交互了。
要检查账户设置是否正确,请运行
sui client active-address
命令:sui client active-address
0x....
该命令将输出你账户的地址,以
0x
开头,后面跟着64个字符。获取测试币
在 devnet 和 testnet 环境中,CLI 提供了一种方式来请求测试币到你的账户,以便你可以与网络进行交互。要请求测试币,请运行
sui client faucet
命令:sui client faucet
Request successful. It can take up to 1 minute to get the coin. Run sui client gas to check your gas coins.
稍等片刻后,你可以运行
sui client balance
命令来检查硬币是否已发送到你的账户:sui client balance
╭────────────────────────────────────────╮ │ Balance of coins owned by this address │ ├────────────────────────────────────────┤ │ ╭──────────────────────────────────╮ │ │ │ coin balance (raw) balance │ │ │ ├──────────────────────────────────┤ │ │ │ Sui 1000000000 1.00 SUI │ │ │ ╰──────────────────────────────────╯ │ ╰────────────────────────────────────────╯
或者,你可以通过运行
sui client objects
命令来查询你的账户拥有的对象。实际输出会有所不同,因为对象 ID 是唯一的,摘要也是唯一的,但结构类似:sui client objects
╭───────────────────────────────────────────────────────────────────────────────────────╮ │ ╭────────────┬──────────────────────────────────────────────────────────────────────╮ │ │ │ objectId │ 0x4ea1303e4f5e2f65fc3709bc0fb70a3035fdd2d53dbcff33e026a50a742ce0de │ │ │ │ version │ 4 │ │ │ │ digest │ nA68oa8gab/CdIRw+240wze8u0P+sRe4vcisbENcR4U= │ │ │ │ objectType │ 0x0000..0002::coin::Coin │ │ │ ╰────────────┴──────────────────────────────────────────────────────────────────────╯ │ ╰───────────────────────────────────────────────────────────────────────────────────────╯
当然现在领测试水比较麻烦,经常出现领不到情况。
可以找第三方的水龙头领,或者直接买。
领水脚本
curl --location --request POST 'https://faucet.testnet.sui.io/gas' \ --header 'Content-Type: application/json' \ --data-raw '{ "FixedAmountRequest": { "recipient": "0x1fdcbc218b29c5d91eb445781016a24658c45825a8469b76f0efb289ccc89f86" } }'
简单完成任务
将以下内容复制到
hello_move.move
文件中,并保存。module hello_move::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"move"), }; transfer(hello_move, sender(ctx)); }
发布上链
sui client publish
到这里,简单几步命令,已经做完训练营的任务。但我认为这还远远不够。
很多问题没有得到回答,比如说,已经发布上链了,但是我们并不知道发不到链的哪个位置了,也不知道怎么调用这个函数,更不知道本应该打印出来的 Hello World 文本在哪。
接下来是加餐!
检查是否上链
首先在发布上链的命令的输出结果中,有四块内容
当包成功发布到链上之后,我们可以开始与之进行交互。为了做到这一点,我们需要找到包的地址(对象ID)。这个地址可以在
Object Changes
输出的 Published Objects
部分找到。每个包的地址都是唯一的,因此您需要从输出中复制它。找到这个地址,把它复制到区块浏览器中

你可以在 Code 中看到反编译的代码。为什么说是反编译的?因为你看包名和变量名都是16进制字符串或者
v0
v1
这种,这是因为源代码在编译过程中已经把这些名字给去掉了,发布到链上的是二进制文件,而将这些二进制文件反编译为代码文件,就会呈现出这种特征。同时我们也可以看到,我们发布的代码,在区块链上就是一个一个包,用我们刚才找到的
对象ID
来定位,官方的包也是用 0x1
0x2
来定位的。而在你把包发布到链上之前,你的包是没有
对象ID
的,这个时候默认用 0x0
来代指。这个特点在 Move.toml
里有写。在区块浏览器里找到了自己发布的包,这样可以算是圆满完成了训练营的任务。
但是还不够,怎么调用我们发布的函数呢?我们做了一个工具上传到链上,光看可没什么意思,要真的能使用才算有意义。
所以接下来,我们改进了程序,发布一个更好交互的,来进一步学习。
To-do List 程序
创建项目
sui move new todo_list
粘贴代码
/// Module: todo_list module todo_list::todo_list { use std::string::String; /// List of todos. Can be managed by the owner and shared with others. public struct TodoList has key, store { id: UID, items: vector<String> } /// Create a new todo list. public fun new(ctx: &mut TxContext): TodoList { let list = TodoList { id: object::new(ctx), items: vector[] }; (list) } /// Add a new todo item to the list. public fun add(list: &mut TodoList, item: String) { list.items.push_back(item); } /// Remove a todo item from the list by index. public fun remove(list: &mut TodoList, index: u64): String { list.items.remove(index) } /// Delete the list and the capability to manage it. public fun delete(list: TodoList) { let TodoList { id, items: _ } = list; id.delete(); } /// Get the number of items in the list. public fun length(list: &TodoList): u64 { list.items.length() } }
发布到链上
sui client publish
发送交易
为了演示与
todo_list
包的交互,我们将发送一个交易来创建一个新的列表并向其中添加一个项目。交易通过sui client ptb
命令发送,它允许充分利用交易块。这个命令可能看起来很庞大和复杂,但我们将逐步解释。准备变量
在构建命令之前,让我们存储将在交易中使用的值。将
0x8....
替换为您已发布的包的地址。MY_ADDRESS
变量将自动从CLI输出中设置为您的地址。export PACKAGE_ID=0x8ce91fae6d724d1593f7ef6d699ec29925daf47e783e28e7cb4773b2486f967d
export MY_ADDRESS=$(sui client active-address)
构建 CLI 中的交易
现在来构建一个实际的交易。该交易将由两部分组成:我们将调用
todo_list
包中的new
函数来创建一个新的列表,然后将列表对象转移到我们的账户。交易将如下所示:sui client ptb \ --gas-budget 100000000 \ --assign sender @$MY_ADDRESS \ --move-call $PACKAGE_ID::todo_list::new \ --assign list \ --transfer-objects "[list]" sender
在这个命令中,我们使用
ptb
子命令来构建一个交易。随后的参数定义了交易将执行的实际命令和操作。我们首先进行的两个调用是实用函数调用,用于设置发送者地址为命令输入,并为交易设置gas预算。# sets the gas budget for the transaction --gas-budget 100000000 \n # registers a variable "sender=@..." --assign sender @$MY_ADDRESS \n
接下来,我们执行对包中函数的实际调用。我们使用
--move-call
,紧接着是包ID、模块名和函数名。在这种情况下,我们调用的是todo_list
包中的new
函数。# calls the "new" function in the "todo_list" package under the $PACKAGE_ID address --move-call $PACKAGE_ID::todo_list::new
我们定义的函数实际上返回一个值,我们需要将其存储起来。我们使用
--assign
命令为返回的值赋予一个名称。在这种情况下,我们将其命名为list
。然后,我们将该对象转移给我们的账户。--move-call $PACKAGE_ID::todo_list::new \ # assigns the result of the "new" function to the "list" variable (from the previous step) --assign list \ # transfers the object to the sender --transfer-objects "[list]" sender
一旦命令构建完成,您可以在终端中运行它。如果一切正确,您应该看到类似于前面章节中的输出。输出将包含交易摘要、交易数据和交易效果。
Transaction Digest: 75BZntxYdLE38AV4jhJGs5izt55dcHxCs9ivhPSqvgYx ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Transaction Data │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Sender: 0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd │ │ Gas Owner: 0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd │ │ Gas Budget: 100000000 MIST │ │ Gas Price: 1000 MIST │ │ Gas Payment: │ │ ┌── │ │ │ ID: 0x0862b75d38ad532b9dab6bfbcb314afd82c636aa5a1974ca45240647f523a846 │ │ │ Version: 239546354 │ │ │ Digest: Hr32AZnxAhBedbzN3HeC91pRrTbgx4zQGTW2aBR8D2pC │ │ └── │ │ │ │ Transaction Kind: Programmable │ │ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ Input Objects │ │ │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ │ │ 0 Pure Arg: Type: address, Value: "0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd" │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ ╭──────────────────────────────────────────────────────────────────────────────────╮ │ │ │ Commands │ │ │ ├──────────────────────────────────────────────────────────────────────────────────┤ │ │ │ 0 MoveCall: │ │ │ │ ┌ │ │ │ │ │ Function: new │ │ │ │ │ Module: todo_list │ │ │ │ │ Package: 0x8ce91fae6d724d1593f7ef6d699ec29925daf47e783e28e7cb4773b2486f967d │ │ │ │ └ │ │ │ │ │ │ │ │ 1 TransferObjects: │ │ │ │ ┌ │ │ │ │ │ Arguments: │ │ │ │ │ Result 0 │ │ │ │ │ Address: Input 0 │ │ │ │ └ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ Signatures: │ │ HbZv4eg8dBjYpUaZXmOH0nuTZps8QHm2jyqOEF2KYIdf/rCQW1wuLfUzrYxvk1+cuP3Xjbm5RZsTGfj0//xhCQ== │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Transaction Effects │ ├───────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Digest: 75BZntxYdLE38AV4jhJGs5izt55dcHxCs9ivhPSqvgYx │ │ Status: Success │ │ Executed Epoch: 645 │ │ │ │ Created Objects: │ │ ┌── │ │ │ ID: 0xc7f47fc94f4594d5341238e529798a2f3433969faa221c812d54a8624a1ccb3c │ │ │ Owner: Account Address ( 0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd ) │ │ │ Version: 239546355 │ │ │ Digest: 3K6bYfeGwpWXPMxogegRrGQegqoG53GQycec8C6k3NHH │ │ └── │ │ Mutated Objects: │ │ ┌── │ │ │ ID: 0x0862b75d38ad532b9dab6bfbcb314afd82c636aa5a1974ca45240647f523a846 │ │ │ Owner: Account Address ( 0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd ) │ │ │ Version: 239546355 │ │ │ Digest: 8uQQ23jHhCvaCs717gQsYSJogHbNp7gZSneWdGwhCQyc │ │ └── │ │ Gas Object: │ │ ┌── │ │ │ ID: 0x0862b75d38ad532b9dab6bfbcb314afd82c636aa5a1974ca45240647f523a846 │ │ │ Owner: Account Address ( 0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd ) │ │ │ Version: 239546355 │ │ │ Digest: 8uQQ23jHhCvaCs717gQsYSJogHbNp7gZSneWdGwhCQyc │ │ └── │ │ Gas Cost Summary: │ │ Storage Cost: 2318000 MIST │ │ Computation Cost: 1000000 MIST │ │ Storage Rebate: 978120 MIST │ │ Non-refundable Storage Fee: 9880 MIST │ │ │ │ Transaction Dependencies: │ │ CA6gjc8en7HwWDh4m1DEA374oke8bzD8h4s2n2s2nSTK │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────╮ │ No transaction block events │ ╰─────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Object Changes │ ├─────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Created Objects: │ │ ┌── │ │ │ ObjectID: 0xc7f47fc94f4594d5341238e529798a2f3433969faa221c812d54a8624a1ccb3c │ │ │ Sender: 0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd │ │ │ Owner: Account Address ( 0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd ) │ │ │ ObjectType: 0x8ce91fae6d724d1593f7ef6d699ec29925daf47e783e28e7cb4773b2486f967d::todo_list::TodoList │ │ │ Version: 239546355 │ │ │ Digest: 3K6bYfeGwpWXPMxogegRrGQegqoG53GQycec8C6k3NHH │ │ └── │ │ Mutated Objects: │ │ ┌── │ │ │ ObjectID: 0x0862b75d38ad532b9dab6bfbcb314afd82c636aa5a1974ca45240647f523a846 │ │ │ Sender: 0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd │ │ │ Owner: Account Address ( 0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd ) │ │ │ ObjectType: 0x2::coin::Coin<0x2::sui::SUI> │ │ │ Version: 239546355 │ │ │ Digest: 8uQQ23jHhCvaCs717gQsYSJogHbNp7gZSneWdGwhCQyc │ │ └── │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Balance Changes │ ├───────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ┌── │ │ │ Owner: Account Address ( 0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd ) │ │ │ CoinType: 0x2::sui::SUI │ │ │ Amount: -2339880 │ │ └── │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
我们要关注的部分是"Object Changes"(对象变化)部分,更具体地说是其中的"Created Objects"(创建的对象)部分。它包含了您创建的
TodoList
的对象 ID、类型和版本信息。我们将使用这个对象 ID 来与对应列表进行交互。在这个示例中,对象 ID 是
0xc7f47fc94f4594d5341238e529798a2f3433969faa221c812d54a8624a1ccb3c
。而拥有者应该是您的账户地址。我们通过在交易的最后一个命令中将对象转移给发送者来实现这一点。另一种测试您是否成功创建了列表的方法是检查账户对象。
sui client objects
它应该有一个类似于以下内容的对象:
│ ╭────────────┬──────────────────────────────────────────────────────────────────────╮ │ │ │ objectId │ 0xc7f47fc94f4594d5341238e529798a2f3433969faa221c812d54a8624a1ccb3c │ │ │ │ version │ 239546355 │ │ │ │ digest │ IlonyI2vGBM43YJzvlgPl4leyGg4oTU0lHwsPuy6mQQ= │ │ │ │ objectType │ 0x8ce9..967d::todo_list::TodoList │ │ │ ╰────────────┴──────────────────────────────────────────────────────────────────────╯ │
将对象传递给函数
我们在上一步中创建的TodoList是一个可以作为其所有者进行交互的对象。您可以在该对象上调用
todo_list
模块中定义的函数。为了演示这一点,我们将向列表中添加一个项目。首先,我们只添加一个项目,然后在第二个交易中添加3个项目并删除另一个项目。请再次检查您是否已经设置了前一步骤中的变量,然后为列表对象添加一个变量。
export LIST_ID=0xc7f47fc94f4594d5341238e529798a2f3433969faa221c812d54a8624a1ccb3c
现在我们可以构建一个交易,向列表中添加一个项目。命令将如下所示:
sui client ptb \ --gas-budget 100000000 \ --move-call $PACKAGE_ID::todo_list::add @$LIST_ID "'Finish the Hello, Sui chapter'"
在这个命令中,我们调用了
todo_list
包中的 add
函数。该函数接受两个参数:列表对象和要添加的项目。项目是一个字符串,所以我们需要用单引号将其包裹起来。该命令将项目添加到列表中。如果一切正确,您应该看到类似于前面章节中的输出。现在,您可以检查列表对象,看看项目是否已经被添加进去了。
sui client object $LIST_ID
输出应该包含您添加的项目。
╭───────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ objectId │ 0xc7f47fc94f4594d5341238e529798a2f3433969faa221c812d54a8624a1ccb3c │ │ version │ 239546356 │ │ digest │ GLwEnPpH4igib4JSrheh2uy8dfHTJ1Tw9bbZVkGs6L1s │ │ objType │ 0x8ce91fae6d724d1593f7ef6d699ec29925daf47e783e28e7cb4773b2486f967d::todo_list::TodoList │ │ owner │ ╭──────────────┬──────────────────────────────────────────────────────────────────────╮ │ │ │ │ AddressOwner │ 0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd │ │ │ │ ╰──────────────┴──────────────────────────────────────────────────────────────────────╯ │ │ prevTx │ 2rSkhE5pqyv3pdqKK9cs8AiSZ8SsU7q8NjoiqNxdwzBh │ │ storageRebate │ 1558000 │ │ content │ ╭───────────────────┬───────────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ │ dataType │ moveObject │ │ │ │ │ type │ 0x8ce91fae6d724d1593f7ef6d699ec29925daf47e783e28e7cb4773b2486f967d::todo_list::TodoList │ │ │ │ │ hasPublicTransfer │ true │ │ │ │ │ fields │ ╭───────┬───────────────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ id │ ╭────┬──────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ id │ 0xc7f47fc94f4594d5341238e529798a2f3433969faa221c812d54a8624a1ccb3c │ │ │ │ │ │ │ │ │ │ ╰────┴──────────────────────────────────────────────────────────────────────╯ │ │ │ │ │ │ │ │ items │ ╭─────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ Finish the Hello, Sui chapter │ │ │ │ │ │ │ │ │ │ ╰─────────────────────────────────╯ │ │ │ │ │ │ │ ╰───────┴───────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ ╰───────────────────┴───────────────────────────────────────────────────────────────────────────────────────────╯ │ ╰───────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

区块浏览器查看也可以看到
可以通过在命令中添加
--json
标志来获取对象的JSON表示形式。(JSON 格式的输出对后续的自动化很有用)
sui client object $LIST_ID --json
{ "objectId": "0xc7f47fc94f4594d5341238e529798a2f3433969faa221c812d54a8624a1ccb3c", "version": "239546356", "digest": "GLwEnPpH4igib4JSrheh2uy8dfHTJ1Tw9bbZVkGs6L1s", "type": "0x8ce91fae6d724d1593f7ef6d699ec29925daf47e783e28e7cb4773b2486f967d::todo_list::TodoList", "owner": { "AddressOwner": "0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd" }, "previousTransaction": "2rSkhE5pqyv3pdqKK9cs8AiSZ8SsU7q8NjoiqNxdwzBh", "storageRebate": "1558000", "content": { "dataType": "moveObject", "type": "0x8ce91fae6d724d1593f7ef6d699ec29925daf47e783e28e7cb4773b2486f967d::todo_list::TodoList", "hasPublicTransfer": true, "fields": { "id": { "id": "0xc7f47fc94f4594d5341238e529798a2f3433969faa221c812d54a8624a1ccb3c" }, "items": [ "Finish the Hello, Sui chapter" ] } } }
链式命令
链接多个命令可以在单个交易中执行。这展示了交易块的威力!使用相同的列表对象,我们将添加三个项目并删除一个项目。命令将如下所示:
sui client ptb \ --gas-budget 100000000 \ --move-call $PACKAGE_ID::todo_list::add @$LIST_ID "'Finish Concepts chapter'" \ --move-call $PACKAGE_ID::todo_list::add @$LIST_ID "'Read the Move Basics chapter'" \ --move-call $PACKAGE_ID::todo_list::add @$LIST_ID "'Learn about Object Model'" \ --move-call $PACKAGE_ID::todo_list::remove @$LIST_ID 0
如果之前的命令都成功执行了,这个命令也应该不会有问题。你可以检查列表对象,看看项目是否已被添加和删除。JSON 格式会更易读一些!
sui client object $LIST_ID --json
{ "objectId": "0xc7f47fc94f4594d5341238e529798a2f3433969faa221c812d54a8624a1ccb3c", "version": "239546357", "digest": "FVkWoBiXf2yZCYh2JATkvPEwKj72vsq65YUTXyEirris", "type": "0x8ce91fae6d724d1593f7ef6d699ec29925daf47e783e28e7cb4773b2486f967d::todo_list::TodoList", "owner": { "AddressOwner": "0x51569ce65a5a275eb27277db2d236136cded7cf9582321a1f4188ac70d2205bd" }, "previousTransaction": "FskXGoFFTeAdQYcntHTdbw9ZX52g3Jmf8LRG2iiWthHq", "storageRebate": "1922800", "content": { "dataType": "moveObject", "type": "0x8ce91fae6d724d1593f7ef6d699ec29925daf47e783e28e7cb4773b2486f967d::todo_list::TodoList", "hasPublicTransfer": true, "fields": { "id": { "id": "0xc7f47fc94f4594d5341238e529798a2f3433969faa221c812d54a8624a1ccb3c" }, "items": [ "Finish Concepts chapter", "Read the Move Basics chapter", "Learn about Object Model" ] } } }
命令不必在同一个包中,也不必操作同一个对象。在单个交易块中,你可以与多个包和对象进行交互。这是一个强大的功能,可以让你在链上构建复杂的交互!
参考文章
致谢:
有关Notion安装或者使用上的问题,欢迎您在底部评论区留言,一起交流~
- Author:无常 Anitya
- URL:https://anitya.fun/article/198b6ca0-c778-80ed-bd48-cc366255e9ac
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts