Client
1 命令说明
sui client
的子命令集是用于跟Sui
网络交互相关的命令,命令非常丰富,以下将进行分类并逐一介绍命令的使用。
可通过help/-h
获取完整的子命令:
$ sui client -h
Client for interacting with the Sui network
Usage: sui client [OPTIONS] [COMMAND]
Commands:
active-address Default address used for commands when none specified
active-env Default environment used for commands when none specified
addresses Obtain the Addresses managed by the client
balance List the coin balance of an address
call Call Move function
chain-identifier Query the chain identifier from the rpc endpoint
dynamic-field Query a dynamic field by its address
envs List all Sui environments
execute-signed-tx Execute a Signed Transaction. This is useful when the user prefers to sign elsewhere and use this command to execute
execute-combined-signed-tx Execute a combined serialized SenderSignedData string
faucet Request gas coin from faucet. By default, it will use the active
address and the active network
gas Obtain all gas objects owned by the address. An address' alias
can be used instead of the address
merge-coin Merge two coin objects into one coin
new-address Generate new address and keypair with keypair scheme flag
{ed25519 | secp256k1 | secp256r1} with optional derivation path,
default to m/44'/784'/0'/0'/0' for ed25519 or m/54'/784'/0'/0/0
for secp256k1 or m/74'/784'/0'/0/0 for secp256r1. Word length can
be { word12 | word15 | word18 | word21 | word24} default to
word12 if not specified
new-env Add new Sui environment
object Get object info
objects Obtain all objects owned by the address. It also accepts an
address by its alias
pay Pay coins to recipients following specified amounts, with input
coins. Length of recipients must be the same as that of amounts
pay-all-sui Pay all residual SUI coins to the recipient with input coins,
after deducting the gas cost. The input coins also include the
coin for gas payment, so no extra gas coin is required
pay-sui Pay SUI coins to recipients following following specified
amounts, with input coins. Length of recipients must be the same
as that of amounts. The input coins also include the coin for gas
payment, so no extra gas coin is required
ptb Run a PTB from the provided args
publish Publish Move modules
split-coin Split a coin object into multiple coins
switch Switch active address and network(e.g., devnet, local rpc server)
tx-block Get the effects of executing the given transaction block
transfer Transfer object
transfer-sui Transfer SUI, and pay gas with the same SUI coin object. If
amount is specified, only the amount is transferred; otherwise
the entire object is transferred
upgrade Upgrade Move modules
verify-bytecode-meter Run the bytecode verifier on the package
verify-source Verify local Move packages against on-chain packages, and
optionally their dependencies
profile-transaction Profile the gas usage of a transaction. Unless an output filepath
is not specified, outputs a file
`gas_profile_{tx_digest}_{unix_timestamp}.json` which can be
opened in a flamegraph tool such as speedscope
replay-transaction Replay a given transaction to view transaction effects. Set
environment variable MOVE_VM_STEP=1 to debug
replay-batch Replay transactions listed in a file
replay-checkpoint Replay all transactions in a range of checkpoints
help Print this message or the help of the given subcommand(s)
2 命令分类
根据命令实现功能分为以下几类:
2.1 链网络类
子命令 | 功能说明 |
---|---|
envs | 查看当前客户端所有配置链网络环境 |
active-env | 获取当前默认环境 |
new-env | 添加链网络环境 |
switch | 切换网络 |
chain-identifier | 获取当前链网络标识 |
2.2 地址类
子命令 | 功能说明 |
---|---|
addresses | 获取当前客户端管理的所有地址 |
active-address | 获取当前默认用户地址 |
new-address | 创建新地址 |
switch | 切换地址 |
2.3 对象类
子命令 | 功能说明 |
---|---|
objects | 获取地址拥有的所有对象 |
object | 获取对象信息 |
transfer | 转移对象 |
dynamic-field | 查询对象的动态域(dynamic field ) |
2.4 COIN类
子命令 | 功能说明 |
---|---|
balance | 获取地址代币余额 |
faucet | 领水 |
gas | 获取地址或别名的所有gas 对象 |
merge-coin | 代币合并 |
split-coin | 代币拆分 |
transfer-sui | 转移SUI |
pay | 支付COIN 到指定地址 |
pay-sui | 支付SUI 到指定地址 |
pay-all-sui | 转移所有SUI 到指定地址 |
2.5 合约类
2.6 交易类
子命令 | 功能说明 |
---|---|
execute-signed-tx | 执行签名交易 |
execute-combined-signed-tx | 执行多签交易 |
tx-block | 获取指定交易快的执行影响(effects ) |
2.7 PTB类
子命令 | 功能说明 |
---|---|
ptb | 根据指定参数执行PTB |
2.8 调优类
子命令 | 功能说明 |
---|---|
profile-transaction | 交易gas 消耗分析 |
replay-transaction | 给定交易重放 |
replay-batch | 批量交易重放 |
replay-checkpoint | 重放指定一段检查点区间内的所有交易 |
3 命令详解
3.1 链网络类
3.1.1 envs
: 查看当前客户端所有配置链网络环境
(1) 命令说明
执行该命令会查看当前客户端所有配置链网络环境,包括环境别名、环境地址、是否为活跃环境。
相关信息来自本地的配置文件: ~/.sui/sui_config/client.yaml
List all Sui environments
(2) 命令使用
$ sui client envs
╭──────────┬───────────────────────────────────────┬────────╮
│ alias │ url │ active │
├──────────┼───────────────────────────────────────┼────────┤
│ devnet │ https://fullnode.devnet.sui.io:443 │ │
│ mainnet │ https://sui-mainnet.nodeinfra.com:443 │ * │
│ testnet │ https://fullnode.testnet.sui.io:443 │ │
╰──────────┴───────────────────────────────────────┴────────╯
3.1.2 active-env
: 获取当前默认环境
(1) 命令说明
执行该命令将获取当前客户端使用的链网络环境。
Default environment used for commands when none specified
(2) 命令使用
$ sui client active-env
mainnet
3.1.3 new-env
: 添加链网络环境
(1) 命令说明
执行该命令将添加新的链网络环境。
Add new Sui environment
(2) 命令使用
- 执行添加命令
$ sui client new-env --alias localnet --rpc http://127.0.0.1:9000
Added new Sui env [localnet] to config.
- 在此查看链网络
$ sui client envs
╭──────────┬───────────────────────────────────────┬────────╮
│ alias │ url │ active │
├──────────┼───────────────────────────────────────┼────────┤
│ devnet │ https://fullnode.devnet.sui.io:443 │ │
│ mainnet │ https://sui-mainnet.nodeinfra.com:443 │ * │
│ localnet │ http://127.0.0.1:9000 │ │
│ testnet │ https://fullnode.testnet.sui.io:443 │ │
╰──────────┴───────────────────────────────────────┴────────╯
可见localnet
网络已经添加进去。
3.1.4 switch
: 切换网络
(1) 命令说明
执行该命令使用不同的参数,可以切换地址和网络,这里我们使用--env
命令进行网络切换。
Switch active address and network(e.g., devnet, local rpc server)
Usage: sui client switch [OPTIONS]
Options:
--address <ADDRESS> An address to be used as the active address for subsequent
commands. It accepts also the alias of the address
--env <ENV> The RPC server URL (e.g., local rpc server, devnet rpc
server, etc) to be used for subsequent commands
(2) 命令使用
$ sui client switch --env localnet
Active environment switched to [localnet]
3.1.5 chain-identifier
: 获取当前链网络标识
(1) 命令说明
执行该命令将会获得当前链网络标识。
(2) 命令使用
$ sui client chain-identifier
35834a8a
3.2 地址类
3.2.1 addresses
: 获取当前客户端管理的所有地址
(1) 命令说明
执行该命令将获取当前客户端管理的所有地址,包括地址别名和地址。 数据来源于本地文件~/.sui/sui_config/sui.aliases
。
注:本地文件
~/.sui/sui_config/sui.aliases
中存储的是地址base64
编码的公钥,~/.sui/sui_config/sui.keystore
存储的是地址私钥
Obtain the Addresses managed by the client
(2) 命令使用
$ sui client addresses --json
{
"activeAddress": "0x5c5882d73a6e5b6ea1743fb028eff5e0d7cc8b7ae123d27856c5fe666d91569a",
"addresses": [
[
"jason",
"0x5c5882d73a6e5b6ea1743fb028eff5e0d7cc8b7ae123d27856c5fe666d91569a"
],
[
"yas",
"0x2d178b9704706393d2630fe6cf9415c2c50b181e9e3c7a977237bb2929f82d19"
],
[
"yoy",
"0xf2e6ffef7d0543e258d4c47a53d6fa9872de4630cc186950accbd83415b009f0"
]
]
}
3.2.2 active-address
: 获取当前默认用户地址
(1) 命令说明
执行该命令将获取当前客户端默认使用的用户地址。
Default address used for commands when none specified
(2) 命令使用
$ sui client active-address
0x5c5882d73a6e5b6ea1743fb028eff5e0d7cc8b7ae123d27856c5fe666d91569a
3.2.3 new-address
: 创建新地址
(1) 命令说明
执行该命令将创建一个新的地址,并返回地址和助记词。
Generate new address and keypair with keypair scheme flag {ed25519 | secp256k1 | secp256r1} with optional derivation path, default to m/44'/784'/0'/0'/0' for ed25519 or m/54'/784'/0'/0/0 for secp256k1 or m/74'/784'/0'/0/0 for secp256r1. Word length can be { word12 | word15 | word18 | word21 | word24} default to word12 if not specified
Usage: sui client new-address [OPTIONS] <KEY_SCHEME> [ALIAS] [WORD_LENGTH] [DERIVATION_PATH]
Arguments:
<KEY_SCHEME>
[ALIAS] The alias must start with a letter and can contain only letters, digits, hyphens (-), or underscores (_)
[WORD_LENGTH]
[DERIVATION_PATH]
(2) 命令使用
$ sui client new-address ed25519 js --json
Keys saved as Base64 with 33 bytes `flag || privkey` ($BASE64_STR).
To see Bech32 format encoding, use `sui keytool export $SUI_ADDRESS` where
$SUI_ADDRESS can be found with `sui keytool list`. Or use `sui keytool convert $BASE64_STR`.
{
"alias": "js",
"address": "0xe760ab0e273b4ec996abe76ce67e895e13064611cb4215d7358f2a63188e1a98",
"keyScheme": "ED25519",
"recoveryPhrase": "dismiss split donor onion hour heavy stand work detail issue room pink lion enroll"
}
3.2.4 switch
: 切换地址
(1) 命令说明
执行该命令使用不同的参数,可以切换地址和网络,这里我们使用--address
命令进行地址切换。
Switch active address and network(e.g., devnet, local rpc server)
Usage: sui client switch [OPTIONS]
Options:
--address <ADDRESS> An address to be used as the active address for subsequent
commands. It accepts also the alias of the address
--env <ENV> The RPC server URL (e.g., local rpc server, devnet rpc
server, etc) to be used for subsequent commands
(2) 命令使用
$ sui client switch --address js
Active address switched to 0xe760ab0e273b4ec996abe76ce67e895e13064611cb4215d7358f2a63188e1a98
3.3 对象类
3.3.1 objects
: 获取地址拥有的所有对象
(1) 命令说明
执行该命令将获取地址拥有的所有对象。
Obtain all objects owned by the address. It also accepts an address by its alias
(2) 命令使用
# Usage: sui client objects [OPTIONS] [owner_address]
$ sui client objects --json
[
{
"data": {
"objectId": "0xcc0b1b68febda7888b7681a70199ab291b38941ee965ed27af1b0bdf8ae79f76",
"version": "25131978",
"digest": "33Ny3AZ3q169QD2uvrso6QtfigyFqN8DccZ1cUJR7v2y",
"type": "0x99bb55e386947db154dcb23b8f39191536c6332b659f3c6aa7596a0cd1f5c4bc::LuckyCafe::Card",
"owner": {
"AddressOwner": "0x5c5882d73a6e5b6ea1743fb028eff5e0d7cc8b7ae123d27856c5fe666d91569a"
},
"previousTransaction": "4qYbEkvQWWshcgyg93NVtHt4hAMqnU9CMt86HJentZ4B",
"storageRebate": "1535200",
"content": {
"dataType": "moveObject",
"type": "0x99bb55e386947db154dcb23b8f39191536c6332b659f3c6aa7596a0cd1f5c4bc::LuckyCafe::Card",
"hasPublicTransfer": true,
"fields": {
"cafe_id": "0x0463f197aa3c90a6c668089267aef6cff0ae3a50ed8144a7da84a49ece45f2e1",
"id": {
"id": "0xcc0b1b68febda7888b7681a70199ab291b38941ee965ed27af1b0bdf8ae79f76"
}
}
}
}
},
......
3.3.2 object
: 获取对象信息
(1) 命令说明
执行该命令将获取指定对象信息。
Get object info
(2) 命令使用
$ sui client object 0xcc0b1b68febda7888b7681a70199ab291b38941ee965ed27af1b0bdf8ae79f76 --json
{
"objectId": "0xcc0b1b68febda7888b7681a70199ab291b38941ee965ed27af1b0bdf8ae79f76",
"version": "25131978",
"digest": "33Ny3AZ3q169QD2uvrso6QtfigyFqN8DccZ1cUJR7v2y",
"type": "0x99bb55e386947db154dcb23b8f39191536c6332b659f3c6aa7596a0cd1f5c4bc::LuckyCafe::Card",
"owner": {
"AddressOwner": "0x5c5882d73a6e5b6ea1743fb028eff5e0d7cc8b7ae123d27856c5fe666d91569a"
},
"previousTransaction": "4qYbEkvQWWshcgyg93NVtHt4hAMqnU9CMt86HJentZ4B",
"storageRebate": "1535200",
"content": {
"dataType": "moveObject",
"type": "0x99bb55e386947db154dcb23b8f39191536c6332b659f3c6aa7596a0cd1f5c4bc::LuckyCafe::Card",
"hasPublicTransfer": true,
"fields": {
"cafe_id": "0x0463f197aa3c90a6c668089267aef6cff0ae3a50ed8144a7da84a49ece45f2e1",
"id": {
"id": "0xcc0b1b68febda7888b7681a70199ab291b38941ee965ed27af1b0bdf8ae79f76"
}
}
}
}
3.3.3 transfer
: 转移对象
(1) 命令说明
执行该命令将指定对象转移给指定地址。
Transfer object
Usage: sui client transfer [OPTIONS] --to <TO> --object-id <OBJECT_ID>
Options:
--to <TO>
Recipient address (or its alias if it's an address in the keystore)
--object-id <OBJECT_ID>
ID of the object to transfer
(2) 命令使用
$ export CARD=0xcc0b1b68febda7888b7681a70199ab291b38941ee965ed27af1b0bdf8ae79f76
$ sui client transfer --to alice --object-id $CARD
# 可见AddressOwner已经进行了转移
$ sui client object 0xcc0b1b68febda7888b7681a70199ab291b38941ee965ed27af1b0bdf8ae79f76 --json
{
"objectId": "0xcc0b1b68febda7888b7681a70199ab291b38941ee965ed27af1b0bdf8ae79f76",
"version": "28078186",
"digest": "2y7xvkF9fKPM2jdmxrwShtFsJXQhH7C17KLXBu2zepPN",
"type": "0x99bb55e386947db154dcb23b8f39191536c6332b659f3c6aa7596a0cd1f5c4bc::LuckyCafe::Card",
"owner": {
"AddressOwner": "0x2d178b9704706393d2630fe6cf9415c2c50b181e9e3c7a977237bb2929f82d19"
},
"previousTransaction": "CUoG2NZT5L94fHqWZNTrAoUs88HDAhyXiSLxL3m9Zn6U",
"storageRebate": "1535200",
"content": {
"dataType": "moveObject",
"type": "0x99bb55e386947db154dcb23b8f39191536c6332b659f3c6aa7596a0cd1f5c4bc::LuckyCafe::Card",
"hasPublicTransfer": true,
"fields": {
"cafe_id": "0x0463f197aa3c90a6c668089267aef6cff0ae3a50ed8144a7da84a49ece45f2e1",
"id": {
"id": "0xcc0b1b68febda7888b7681a70199ab291b38941ee965ed27af1b0bdf8ae79f76"
}
}
}
}
3.3.4 dynamic-field
: 查询对象的动态域
(1) 命令说明
执行该命令将查询指定对象动态域。
Query a dynamic field by its address
Usage: sui client dynamic-field [OPTIONS] <object_id>
Arguments:
<object_id> The ID of the parent object
Options:
--cursor <CURSOR> Optional paging cursor
--limit <LIMIT> Maximum item returned per page [default: 50]
--json Return command outputs in json format
(2) 命令使用
$ sui client dynamic-field 0x9e2d68fb1263c6addde282640438c6910c219922de5e07fd2b1a94fcf40b6214
3.4 COIN类
3.4.1 balance
: 获取地址代币余额
(1) 命令说明
执行该命令将获取当前地址代币余额。
List the coin balance of an address
Usage: sui client balance [OPTIONS] [ADDRESS]
Arguments:
[ADDRESS] Address (or its alias)
Options:
--coin-type <COIN_TYPE> Show balance for the specified coin (e.g.,
0x2::sui::SUI). All coins will be shown if none is
passed
--with-coins Show a list with each coin's object ID and balance
(2) 命令使用
- 获取代币余额
$ sui client balance
╭───────────────────────────────────────────────╮
│ Balance of coins owned by this address │
├───────────────────────────────────────────────┤
│ ╭───────────────────────────────────────────╮ │
│ │ coin balance (raw) balance │ │
│ ├───────────────────────────────────────────┤ │
│ │ Sui 14915416944 14.91 SUI │ │
│ │ RZX-name 10000 100.00 RZX-sym │ │
│ ╰───────────────────────────────────────────╯ │
╰───────────────────────────────────────────────╯
- 获取指定代币余额
$ sui client balance --coin-type 0x2::sui::SUI
╭────────────────────────────────────────╮
│ Balance of coins owned by this address │
├────────────────────────────────────────┤
│ ╭──────────────────────────────────╮ │
│ │ coin balance (raw) balance │ │
│ ├──────────────────────────────────┤ │
│ │ Sui 14915416944 14.91 SUI │ │
│ ╰──────────────────────────────────╯ │
╰────────────────────────────────────────╯
- 获取每个代币对象ID和余额
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Balance of coins owned by this address │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ╭────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ Sui: 1 coin, Balance: 14915416944 (14.91 SUI SUI) │ │
│ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │
│ │ coinId balance (raw) balance │ │
│ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │
│ │ 0x043286ba5f16a930c04014e6a8790329a36f01103768055d9daace7cb2466cba 14915416944 14.91 SUI │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ RZX-name: 1 coin, Balance: 10000 (100.00 RZX-sym RZX-sym) │ │
│ ├─────────────────────────────────────────────────────────────────────────────────────────────────────┤ │
│ │ coinId balance (raw) balance │ │
│ ├─────────────────────────────────────────────────────────────────────────────────────────────────────┤ │
│ │ 0x79985fae7d22dffac0a1f31e8bc90d52440af2a06242de55f99fe646df808ff7 10000 100.00 RZX-sym │ │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
╰─────────────────────
3.4.2 faucet
: 领水
(1) 命令说明
执行该命令将领取开发网或测试网水龙头中的代币
Request gas coin from faucet. By default, it will use the active address and the active
network
Usage: sui client faucet [OPTIONS]
Options:
--address <ADDRESS> Address (or its alias)
(2) 命令使用
$ 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.
3.4.3 gas
: 获取地址或别名的所有gas
对象
(1) 命令说明
执行该命令将获取当前地址或别名的所有gas
对象。
Obtain all gas objects owned by the address. An address' alias can be used
instead of the address
Usage: sui client gas [OPTIONS] [owner_address]
Arguments:
[owner_address] Address (or its alias) owning the objects
(2) 命令使用
$ sui client gas
╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0x07904d4deba1a822d52a674205548b36b28859620282479144454d3c096ffa15 │ 10000000000 │ 10.00 │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯
3.4.4 merge-coin
: 代币合并
(1) 命令说明
执行该命令将合并两个代币对象。
Merge two coin objects into one coin
Usage: sui client merge-coin [OPTIONS] --primary-coin <PRIMARY_COIN> --coin-to-merge <COIN_TO_MERGE>
Options:
--primary-coin <PRIMARY_COIN>
The address of the coin to merge into
--coin-to-merge <COIN_TO_MERGE>
The address of the coin to be merged
(2) 命令使用
- 合并前,查询gas
$ sui client gas
╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0x07904d4deba1a822d52a674205548b36b28859620282479144454d3c096ffa15 │ 10000000000 │ 10.00 │
│ 0x9094f1af0b746bc2ee9c4c11621910aa9342bc5b9d1040bdf0dc8886fba40824 │ 10000000000 │ 10.00 │
│ 0xd0c4c7f1d3056114ff378a5504dfb035a9a5254e1e3fd3eb84f562100e7a65b8 │ 10000000000 │ 10.00 │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯
- 执行合并
$ export COIN1=0x07904d4deba1a822d52a674205548b36b28859620282479144454d3c096ffa15
$ export COIN2=0x9094f1af0b746bc2ee9c4c11621910aa9342bc5b9d1040bdf0dc8886fba40824
$ sui client merge-coin --primary-coin $COIN1 --coin-to-merge $COIN2
- 合并后,查询gas
可见
COIN2
已经合并到了COIN1
中。
╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0x07904d4deba1a822d52a674205548b36b28859620282479144454d3c096ffa15 │ 20000000000 │ 20.00 │
│ 0xd0c4c7f1d3056114ff378a5504dfb035a9a5254e1e3fd3eb84f562100e7a65b8 │ 9999958360 │ 9.99 │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯
3.4.5 split-coin
: 代币拆分
(1) 命令说明
执行该命令将拆分一个代币对象。
Split a coin object into multiple coins
Usage: sui client split-coin [OPTIONS] --coin-id <COIN_ID> <--amounts <AMOUNTS>...|--count <COUNT>>
Options:
--coin-id <COIN_ID>
ID of the coin object to split
--amounts <AMOUNTS>...
Specific amounts to split out from the coin
--count <COUNT>
Count of equal-size coins to split into
(2) 命令使用
- 按指定数量拆分
$ export COIN=0x07904d4deba1a822d52a674205548b36b28859620282479144454d3c096ffa15
$ sui client split-coin --coin-id $COIN --amounts 100000 200000
$ sui client gas
╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0x07904d4deba1a822d52a674205548b36b28859620282479144454d3c096ffa15 │ 19999700000 │ 19.99 │
│ 0xc5ec8a908d629218dc3d01faf04f52f535747c2c40e3d57e62628a5514ad83ff │ 200000 │ 0.00 │
│ 0xfbc39da4b681f4c2824e49dad479b38b8f2890a2996385aef06210094e140697 │ 100000 │ 0.00 │
│ 0xd0c4c7f1d3056114ff378a5504dfb035a9a5254e1e3fd3eb84f562100e7a65b8 │ 9996962600 │ 9.99 │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯
- 按份数拆分
$ export COIN=0xfbc39da4b681f4c2824e49dad479b38b8f2890a2996385aef06210094e140697
$ sui client split-coin --coin-id $COIN --count 2
$ sui client gas
╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0xfbc39da4b681f4c2824e49dad479b38b8f2890a2996385aef06210094e140697 │ 50000 │ 0.00 │
│ 0x52df2bade5d24245a66782cd0da27dcfa0daaf9a322cd880364c9aaedb14bc41 │ 50000 │ 0.00 │
│ 0xc5ec8a908d629218dc3d01faf04f52f535747c2c40e3d57e62628a5514ad83ff │ 200000 │ 0.00 │
│ 0x07904d4deba1a822d52a674205548b36b28859620282479144454d3c096ffa15 │ 19997692240 │ 19.99 │
│ 0xd0c4c7f1d3056114ff378a5504dfb035a9a5254e1e3fd3eb84f562100e7a65b8 │ 9996962600 │ 9.99 │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯
3.4.6 transfer-sui
: 转移SUI
(1) 命令说明
执行该命令将转移SUI
到另一个地址。
Transfer SUI, and pay gas with the same SUI coin object. If amount is
specified, only the amount is transferred; otherwise the entire object is
transferred
Usage: sui client transfer-sui [OPTIONS] --to <TO> --sui-coin-object-id <SUI_COIN_OBJECT_ID>
Options:
--to <TO>
Recipient address (or its alias if it's an address in the keystore)
--sui-coin-object-id <SUI_COIN_OBJECT_ID>
ID of the coin to transfer. This is also the gas object
--amount <AMOUNT>
The amount to transfer, if not specified, the entire coin object
will be transferred
(2) 命令使用
- 转移指定数量
$ sui client gas alice
╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0x05b1b5c60d1b777a5dfc7d5a32874a563f303b1902c0fcd7ea7ab2bd6c0dc29e │ 996016240 │ 0.99 │
│ 0x23accfba5fd1743b042c7c0a1596cf346b986c3f1844585ab1c8058baeca00a8 │ 250000000 │ 0.25 │
│ 0x2fcab6efdd3c96746d3e0bc2dc27995b0c68797bf439fc797b2c96181ab426e3 │ 250000000 │ 0.25 │
│ 0x7d233de155d5a58855447b3ae165e9ec605109861ce14f07f63bd83eb01a4856 │ 250000000 │ 0.25 │
│ 0xd2e2c66fa2d0b0ee4316987a7b1d9e004ce56ef21ee92ba28f8c094097d1bbbf │ 250000000 │ 0.25 │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯
$ sui client gas bob
No gas coins are owned by this address
$ export COIN=0xd2e2c66fa2d0b0ee4316987a7b1d9e004ce56ef21ee92ba28f8c094097d1bbbf
$ sui client transfer-sui --to bob --sui-coin-object-id $COIN --amount 50000000
$ sui client gas alice
╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0x05b1b5c60d1b777a5dfc7d5a32874a563f303b1902c0fcd7ea7ab2bd6c0dc29e │ 996016240 │ 0.99 │
│ 0x23accfba5fd1743b042c7c0a1596cf346b986c3f1844585ab1c8058baeca00a8 │ 250000000 │ 0.25 │
│ 0x2fcab6efdd3c96746d3e0bc2dc27995b0c68797bf439fc797b2c96181ab426e3 │ 250000000 │ 0.25 │
│ 0x7d233de155d5a58855447b3ae165e9ec605109861ce14f07f63bd83eb01a4856 │ 250000000 │ 0.25 │
│ 0xd2e2c66fa2d0b0ee4316987a7b1d9e004ce56ef21ee92ba28f8c094097d1bbbf │ 198002120 │ 0.19 │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯
$ sui client gas bob
╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0x724b02db0f8e50aced87f8871d808a4eca06e132345faa57658cd4d1fd12d655 │ 50000000 │ 0.05 │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯
- 全部转移
$ export COIN=0x7d233de155d5a58855447b3ae165e9ec605109861ce14f07f63bd83eb01a4856
$ sui client transfer-sui --to bob --sui-coin-object-id $COIN
$ sui client gas alice
╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0x05b1b5c60d1b777a5dfc7d5a32874a563f303b1902c0fcd7ea7ab2bd6c0dc29e │ 996016240 │ 0.99 │
│ 0x23accfba5fd1743b042c7c0a1596cf346b986c3f1844585ab1c8058baeca00a8 │ 250000000 │ 0.25 │
│ 0x2fcab6efdd3c96746d3e0bc2dc27995b0c68797bf439fc797b2c96181ab426e3 │ 250000000 │ 0.25 │
│ 0xd2e2c66fa2d0b0ee4316987a7b1d9e004ce56ef21ee92ba28f8c094097d1bbbf │ 198002120 │ 0.19 │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯
$ sui client gas bob
╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0x724b02db0f8e50aced87f8871d808a4eca06e132345faa57658cd4d1fd12d655 │ 50000000 │ 0.05 │
│ 0x7d233de155d5a58855447b3ae165e9ec605109861ce14f07f63bd83eb01a4856 │ 248990120 │ 0.24 │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯
3.4.7 pay
: 支付COIN
到指定地址
(1) 命令说明
执行该命令将支付COIN
到指定地址,支持批量转账,接受地址个数与转账金额个数必须相同。
Pay coins to recipients following specified amounts, with input
coins. Length of recipients must be the same as that of amounts
Usage: sui client pay [OPTIONS]
Options:
--input-coins <INPUT_COINS>...
The input coins to be used for pay recipients, following
the specified amounts
--recipients <RECIPIENTS>...
The recipient addresses, must be of same length as
amounts. Aliases of addresses are also accepted as input
--amounts <AMOUNTS>...
The amounts to be paid, following the order of
recipients
(2) 命令使用
- 执行转账命令
分别给
Alice
和Bob
转账100
和200 RZX
。
$ export COIN_ID=0x79985fae7d22dffac0a1f31e8bc90d52440af2a06242de55f99fe646df808ff7
$ sui client pay --input-coins $COIN_ID --recipients alice bob --amounts 100 200
- 查看Alice地址当前余额
╭─────────────────────────────────────────────╮
│ Balance of coins owned by this address │
├─────────────────────────────────────────────┤
│ ╭─────────────────────────────────────────╮ │
│ │ coin balance (raw) balance │ │
│ ├─────────────────────────────────────────┤ │
│ │ Sui 1694018460 1.69 SUI │ │
│ │ RZX-name 100 1.00 RZX-sym │ │
│ ╰─────────────────────────────────────────╯ │
╰─────────────────────────────────────────────╯
- 查看Bob地址当前余额
╭─────────────────────────────────────────────╮
│ Balance of coins owned by this address │
├─────────────────────────────────────────────┤
│ ╭─────────────────────────────────────────╮ │
│ │ coin balance (raw) balance │ │
│ ├─────────────────────────────────────────┤ │
│ │ Sui 298990320 0.29 SUI │ │
│ │ RZX-name 200 2.00 RZX-sym │ │
│ ╰─────────────────────────────────────────╯ │
╰─────────────────────────────────────────────╯
3.4.8 pay-sui
: 支付SUI
到指定地址
(1) 命令说明
执行该命令将支付SUI
到指定地址,支持批量转账,且可以支持多个COIN
会进行合并后再转币。
Pay SUI coins to recipients following following specified amounts, with input
coins. Length of recipients must be the same as that of amounts. The input
coins also include the coin for gas payment, so no extra gas coin is required
Usage: sui client pay-sui [OPTIONS]
Options:
--input-coins <INPUT_COINS>...
The input coins to be used for pay recipients, including the gas
coin
--recipients <RECIPIENTS>...
The recipient addresses, must be of same length as amounts. Aliases
of addresses are also accepted as input
--amounts <AMOUNTS>...
The amounts to be paid, following the order of recipients
(2) 命令使用
- 单地址转
$ export COIN_ID=0x241d78606cb3b7d2f880854c49781e7c537d318a52c499faef24e101455adf9a
$ sui client pay-sui --input-coins $COIN_ID --recipients alice --amounts 10000
$ sui client gas alice
╭────────────────────────────────────────────────────────────────────┬────────────╮
│ gasCoinId │ gasBalance │
├────────────────────────────────────────────────────────────────────┼────────────┤
│ 0x73166aad134319e9c26b19ec6ed0ce419812a7e2612c9ea0e1b93767de423c4d │ 10000 │
╰────────────────────────────────────────────────────────────────────┴────────────╯
$ sui client gas jason
╭────────────────────────────────────────────────────────────────────┬────────────╮
│ gasCoinId │ gasBalance │
├────────────────────────────────────────────────────────────────────┼────────────┤
│ 0x241d78606cb3b7d2f880854c49781e7c537d318a52c499faef24e101455adf9a │ 3760487788 │
│ 0x70b96720fadb6aa45620ab84efd9139e4674057207c93e4375350ec695865fab │ 988221840 │
╰────────────────────────────────────────────────────────────────────┴────────────╯
- 多地址转
$ sui client pay-sui --input-coins $COIN_ID --recipients alice bob --amounts 10000 10000
$ sui client gas alice
╭────────────────────────────────────────────────────────────────────┬────────────╮
│ gasCoinId │ gasBalance │
├────────────────────────────────────────────────────────────────────┼────────────┤
│ 0x73166aad134319e9c26b19ec6ed0ce419812a7e2612c9ea0e1b93767de423c4d │ 10000 │
│ 0xb6013d96900f73c43654a48d5c1aef39838513ec33a189593f962e31f5bc7898 │ 10000 │
╰────────────────────────────────────────────────────────────────────┴────────────╯
$ sui client gas bob
╭────────────────────────────────────────────────────────────────────┬────────────╮
│ gasCoinId │ gasBalance │
├────────────────────────────────────────────────────────────────────┼────────────┤
│ 0xedca429699b178481b88e39502ed39bd322e315c582a70520bd32930a25dd758 │ 10000 │
╰────────────────────────────────────────────────────────────────────┴────────────╯
- 合并后转
若指定多个
coin
的话,会先将这些coin
合并后,再进行转币。
$ export COIN_ID2=0x70b96720fadb6aa45620ab84efd9139e4674057207c93e4375350ec695865fab
$ sui client pay-sui --input-coins $COIN_ID $COIN_ID2 --recipients alice bob --amounts 20000
80000
$ sui client gas jason
╭────────────────────────────────────────────────────────────────────┬────────────╮
│ gasCoinId │ gasBalance │
├────────────────────────────────────────────────────────────────────┼────────────┤
│ 0x241d78606cb3b7d2f880854c49781e7c537d318a52c499faef24e101455adf9a │ 4743595988 │
╰────────────────────────────────────────────────────────────────────┴────────────╯
$ sui client gas alice
╭────────────────────────────────────────────────────────────────────┬────────────╮
│ gasCoinId │ gasBalance │
├────────────────────────────────────────────────────────────────────┼────────────┤
│ 0x73166aad134319e9c26b19ec6ed0ce419812a7e2612c9ea0e1b93767de423c4d │ 10000 │
│ 0xb6013d96900f73c43654a48d5c1aef39838513ec33a189593f962e31f5bc7898 │ 10000 │
│ 0xbfe36b88a30be6bf814c26f7aa4ebeedd4c4a3a189238ba8ce2e712fd5eecc31 │ 20000 │
╰────────────────────────────────────────────────────────────────────┴────────────╯
$ sui client gas bob
╭────────────────────────────────────────────────────────────────────┬────────────╮
│ gasCoinId │ gasBalance │
├────────────────────────────────────────────────────────────────────┼────────────┤
│ 0xac824c384f0bab18bfff13da09c8ba9e65607c6918076b0f90005b5034071f92 │ 80000 │
│ 0xedca429699b178481b88e39502ed39bd322e315c582a70520bd32930a25dd758 │ 10000 │
╰────────────────────────────────────────────────────────────────────┴────────────╯
3.4.9 pay-all-sui
: 支付所有SUI
到指定地址
(1) 命令说明
执行该命令会将指定地址的所有SUI
转移到指定地址。
Pay all residual SUI coins to the recipient with input coins, after deducting
the gas cost. The input coins also include the coin for gas payment, so no
extra gas coin is required
Usage: sui client pay-all-sui [OPTIONS] --recipient <RECIPIENT>
Options:
--input-coins <INPUT_COINS>...
The input coins to be used for pay recipients, including the gas
coin
--recipient <RECIPIENT>
The recipient address (or its alias if it's an address in the
keystore)
(2) 命令使用
$ export COIN_ID=0x241d78606cb3b7d2f880854c49781e7c537d318a52c499faef24e101455adf9a
$ sui client pay-all-sui --input-coins $COIN_ID --recipient alice
$ sui client gas jason
No gas coins are owned by this address
$ sui client gas alice
╭────────────────────────────────────────────────────────────────────┬────────────╮
│ gasCoinId │ gasBalance │
├────────────────────────────────────────────────────────────────────┼────────────┤
│ 0x241d78606cb3b7d2f880854c49781e7c537d318a52c499faef24e101455adf9a │ 4742586108 │
│ 0x73166aad134319e9c26b19ec6ed0ce419812a7e2612c9ea0e1b93767de423c4d │ 10000 │
│ 0xb6013d96900f73c43654a48d5c1aef39838513ec33a189593f962e31f5bc7898 │ 10000 │
│ 0xbfe36b88a30be6bf814c26f7aa4ebeedd4c4a3a189238ba8ce2e712fd5eecc31 │ 20000 │
╰────────────────────────────────────────────────────────────────────┴────────────╯
3.5 合约类
3.5.1 publish
: 部署合约
(1) 命令说明
执行该命令会将指定目录(默认当前目录)下的Move
合约编译成字节码,并将字节码部署到链上。
Publish Move modules
Usage: sui client publish [OPTIONS] [package_path]
Arguments:
[package_path] Path to directory containing a Move package [default: .]
(2) 命令使用
- 执行该命令会创建:
PackageID
,后续在调用合约方法或升级合约都会使用到。 - 如果在
init
合约构造方法中有创建Object
,也会输出对应ObjectId
$ sui client publish
3.5.2 call
: 调用合约方法
(1) 命令说明
执行该命令会调用指定合约的指定方法,并返回执行结果。
--package
指定调用的合约包名--module
指定调用的合约模块名--function
指定调用的合约方法名--args
指定调用方法的参数(可选)--type-args
指定泛型参数类型(可选)
Call Move function
Usage: sui client call [OPTIONS] --package <PACKAGE> --module <MODULE> --function <FUNCTION>
Options:
--package <PACKAGE>
Object ID of the package, which contains the module
--module <MODULE>
The name of the module in the package
--function <FUNCTION>
Function name in module
--type-args <TYPE_ARGS>...
Type arguments to the generic function being called. All must be
specified, or the call will fail
--args <ARGS>...
Simplified ordered args like in the function syntax ObjectIDs,
Addresses must be hex strings
(2) 命令使用
$ client call --function claim_red_packet --package $PACKAGE_ID --module red_packet --type-args 0x2::sui::SUI --args $RED_POCKET $WEATHER_ORACLE 0x6
3.5.3 upgrade
: 升级合约
(1) 命令说明
执行该命令会将指定目录(默认当前目录)下的修改后的Move
合约编译成字节码,并将字节码升级链上合约。
Upgrade Move modules
Usage: sui client upgrade [OPTIONS] --upgrade-capability <UPGRADE_CAPABILITY> [package_path]
Arguments:
[package_path] Path to directory containing a Move package [default: .]
(2) 命令使用
$ sui client upgrade --upgrade-capability $UPGRADE_CAP_ID
3.6 交易类
3.6.1 execute-signed-tx
: 执行签名交易
(1) 命令说明
执行该命令可以执行已经签名交易。
Execute a Signed Transaction. This is useful when the user prefers to sign elsewhere and use this command
to execute
Usage: sui client execute-signed-tx [OPTIONS] --tx-bytes <TX_BYTES>
Options:
--tx-bytes <TX_BYTES> BCS serialized transaction data bytes without its type tag, as base64
encoded string. This is the output of sui client command using
--serialize-unsigned-transaction
--signatures <SIGNATURES> A list of Base64 encoded signatures `flag || signature || pubkey`
(2) 命令使用
- 构造待签名交易
$ sui client pay --input-coins $COIN_ID --recipients alice --amounts 500 --serialize-unsigned-transaction
AAADAQB5mF+ufSLf+sCh8x6LyQ1SRAryoGJC3lX5n+ZG34CP95RwrAEAAAAAILvEC/HKvJqm/K/PIvvqw3z+C53wDTkrF2SHvVugWXHFAAj0AQAAAAAAAAAgaYcvxHgfEV4I9y3TfeEhbEMa/qT6pLeU5TJ9pZq85oECAgEAAAEBAQABAQMAAAAAAQIAXFiC1zpuW26hdD+wKO/14NfMi3rhI9J4VsX+Zm2RVpoBBDKGul8WqTDAQBTmqHkDKaNvARA3aAVdnarOfLJGbLqUcKwBAAAAACB0eN1gH6aZ1wcAk4XFWk41okSYHd6bdQQETp27SRBN01xYgtc6bltuoXQ/sCjv9eDXzIt64SPSeFbF/mZtkVaa6AMAAAAAAADYUEQAAAAAAAA=
- 进行交易签名
$ export RAW_TX_DATA=AAADAQB5mF+ufSLf+sCh8x6LyQ1SRAryoGJC3lX5n+ZG34CP95RwrAEAAAAAILvEC/HKvJqm/K/PIvvqw3z+C53wDTkrF2SHvVugWXHFAAj0AQAAAAAAAAAgaYcvxHgfEV4I9y3TfeEhbEMa/qT6pLeU5TJ9pZq85oECAgEAAAEBAQABAQMAAAAAAQIAXFiC1zpuW26hdD+wKO/14NfMi3rhI9J4VsX+Zm2RVpoBBDKGul8WqTDAQBTmqHkDKaNvARA3aAVdnarOfLJGbLqUcKwBAAAAACB0eN1gH6aZ1wcAk4XFWk41okSYHd6bdQQETp27SRBN01xYgtc6bltuoXQ/sCjv9eDXzIt64SPSeFbF/mZtkVaa6AMAAAAAAADYUEQAAAAAAAA=
$ sui keytool sign --address jason --data $RAW_TX_DATA
╭──────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ suiAddress │ 0x5c5882d73a6e5b6ea1743fb028eff5e0d7cc8b7ae123d27856c5fe666d91569a │
│ rawTxData │ AAADAQB5mF+ufSLf+sCh8x6LyQ1SRAryoGJC3lX5n+ZG34CP95RwrAEAAAAAILvEC/HKvJqm/K/PIvvqw3z+C53wDTkrF2SHvVugWXHFAAj0AQAAAAAAAAAgaYcvxHgfEV4I9y3TfeEhbEMa/qT6pLeU5TJ9pZq8 │
│ │ 5oECAgEAAAEBAQABAQMAAAAAAQIAXFiC1zpuW26hdD+wKO/14NfMi3rhI9J4VsX+Zm2RVpoBBDKGul8WqTDAQBTmqHkDKaNvARA3aAVdnarOfLJGbLqUcKwBAAAAACB0eN1gH6aZ1wcAk4XFWk41okSYHd6bdQQE │
│ │ Tp27SRBN01xYgtc6bltuoXQ/sCjv9eDXzIt64SPSeFbF/mZtkVaa6AMAAAAAAADYUEQAAAAAAAA= │
│ intent │ ╭─────────┬─────╮ │
│ │ │ scope │ 0 │ │
│ │ │ version │ 0 │ │
│ │ │ app_id │ 0 │ │
│ │ ╰─────────┴─────╯ │
│ rawIntentMsg │ AAAAAAADAQB5mF+ufSLf+sCh8x6LyQ1SRAryoGJC3lX5n+ZG34CP95RwrAEAAAAAILvEC/HKvJqm/K/PIvvqw3z+C53wDTkrF2SHvVugWXHFAAj0AQAAAAAAAAAgaYcvxHgfEV4I9y3TfeEhbEMa/qT6pLeU5TJ9 │
│ │ pZq85oECAgEAAAEBAQABAQMAAAAAAQIAXFiC1zpuW26hdD+wKO/14NfMi3rhI9J4VsX+Zm2RVpoBBDKGul8WqTDAQBTmqHkDKaNvARA3aAVdnarOfLJGbLqUcKwBAAAAACB0eN1gH6aZ1wcAk4XFWk41okSYHd6b │
│ │ dQQETp27SRBN01xYgtc6bltuoXQ/sCjv9eDXzIt64SPSeFbF/mZtkVaa6AMAAAAAAADYUEQAAAAAAAA= │
│ digest │ m2QJPh0Ez2FsPhhCbkdVpXeXD2PkAQUgJGw3m4hIyTw= │
│ suiSignature │ AMmljxE4qrgfWYsCk00KtAm60f0bCJt1Qpy0kkg8yv997IxnBq0v3YcXCc9lKponq6BztRa5KI8jTpaep8yaPwGIIWyPVESl2t0z8FQnUdfJFGkkHr/YUBwVWQtnZBZycQ== │
╰──────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
- 发送已交易签名
$ export SIGN=AMmljxE4qrgfWYsCk00KtAm60f0bCJt1Qpy0kkg8yv997IxnBq0v3YcXCc9lKponq6BztRa5KI8jTpaep8yaPwGIIWyPVESl2t0z8FQnUdfJFGkkHr/YUBwVWQtnZBZycQ==
$ sui client execute-signed-tx --tx-bytes $RAW_TX_DATA --signatures $SIGN
- 查看Alice地址当前余额,可以看到余额发生的变化
╭─────────────────────────────────────────────╮
│ Balance of coins owned by this address │
├─────────────────────────────────────────────┤
│ ╭─────────────────────────────────────────╮ │
│ │ coin balance (raw) balance │ │
│ ├─────────────────────────────────────────┤ │
│ │ Sui 3931920823 3.93 SUI │ │
│ │ RZX-name 500 5.00 RZX-sym │ │
│ ╰─────────────────────────────────────────╯ │
╰─────────────────────────────────────────────╯
3.6.2 execute-combined-signed-tx
: 执行联合签名交易
(1) 命令说明
Execute a combined serialized SenderSignedData string
Usage: sui client execute-combined-signed-tx [OPTIONS] --signed-tx-bytes <SIGNED_TX_BYTES>
Options:
--signed-tx-bytes <SIGNED_TX_BYTES>
BCS serialized sender signed data, as base64 encoded string. This is the output of sui client
command using --serialize-signed-transaction
(2) 命令使用
- 构造联合签名交易
$ sui client pay --input-coins $COIN_ID --recipients alice --amounts 800 --serialize-si
gned-transaction
AQAAAAAAAwEAeZhfrn0i3/rAofMei8kNUkQK8qBiQt5V+Z/mRt+Aj/eVcKwBAAAAACCJUku+MB0abKgwUUGVSlr0uGAnfPaY9d40jepHg5vwwAAIIAMAAAAAAAAAIGmHL8R4HxFeCPct033hIWxDGv6k+qS3lOUyfaWavOaBAgIBAAABAQEAAQEDAAAAAAECAFxYgtc6bltuoXQ/sCjv9eDXzIt64SPSeFbF/mZtkVaaAQQyhrpfFqkwwEAU5qh5AymjbwEQN2gFXZ2qznyyRmy6lXCsAQAAAAAgFcDqz+koiG/Vz+IQRUcK59xWHRMppgnk6im7FFK1NptcWILXOm5bbqF0P7Ao7/Xg18yLeuEj0nhWxf5mbZFWmugDAAAAAAAA2FBEAAAAAAAAAWEAmRLC932b4vydYmAhGRKuoQxcd9baeMDh77jK9X2aEKfMKi8kHrmNzCS6QR7PN1vPEZB2AnK9mJIl6rCduUh5DIghbI9URKXa3TPwVCdR18kUaSQev9hQHBVZC2dkFnJx
- 发送联合签名交易
$ export SIGNED_TX_BYTES=AQAAAAAAAwEAeZhfrn0i3/rAofMei8kNUkQK8qBiQt5V+Z/mRt+Aj/eVcKwBAAAAACCJUku+MB0abKgwUUGVSlr0uGAnfPaY9d40jepHg5vwwAAIIAMAAAAAAAAAIGmHL8R4HxFeCPct033hIWxDGv6k+qS3lOUyfaWavOaBAgIBAAABAQEAAQEDAAAAAAECAFxYgtc6bltuoXQ/sCjv9eDXzIt64SPSeFbF/mZtkVaaAQQyhrpfFqkwwEAU5qh5AymjbwEQN2gFXZ2qznyyRmy6lXCsAQAAAAAgFcDqz+koiG/Vz+IQRUcK59xWHRMppgnk6im7FFK1NptcWILXOm5bbqF0P7Ao7/Xg18yLeuEj0nhWxf5mbZFWmugDAAAAAAAA2FBEAAAAAAAAAWEAmRLC932b4vydYmAhGRKuoQxcd9baeMDh77jK9X2aEKfMKi8kHrmNzCS6QR7PN1vPEZB2AnK9mJIl6rCduUh5DIghbI9URKXa3TPwVCdR18kUaSQev9hQHBVZC2dkFnJx
$ sui client execute-combined-signed-tx --signed-tx-bytes $SIGNED_TX_BYTES
- 查看Alice地址当前余额,可以看到余额发生的变化
╭──────────────────────────────────────────────╮
│ Balance of coins owned by this address │
├──────────────────────────────────────────────┤
│ ╭──────────────────────────────────────────╮ │
│ │ coin balance (raw) balance │ │
│ ├──────────────────────────────────────────┤ │
│ │ Sui 3931920823 3.93 SUI │ │
│ │ RZX-name 1300 13.00 RZX-sym │ │
│ ╰──────────────────────────────────────────╯ │
╰──────────────────────────────────────────────╯
3.6.3 tx-block
: 获取指定交易的执行影响
(1) 命令说明
执行该命令可以获取指定交易的执行影响。
Get the effects of executing the given transaction block
Usage: sui client tx-block [OPTIONS] <digest>
Arguments:
<digest> Digest of the transaction block
(2) 命令使用
$ sui client tx-block HzG4Z3vv4MA6rgPVJRUZmLLfNJJhEyE3iWK6LHjTYNBG
3.7 PTB类
PTB
即可编程交易块,是SUI
提供的一个非常强大的一个功能,它允许在一个交易中执行多种操作,甚至去调用不同的合约。- 直接通过命令行脚本的方式去创建和执行
PTB
,可以方便开发人员在不用通过SDK
写代码的情况下便能构建和执行PTB
,也为自动化任务场景提供了很大的灵活性和便利性。 - 由于
ptb
命令比较复杂,单独自成一类,进行讲解
3.7.1 ptb
: 根据指定参数执行PTB
(1) 命令说明
执行该命令可以构建、预览和执行PTB
,下面将对主要的命令行参数逐一进行说明。
Build, preview, and execute programmable transaction blocks. Depending on your
shell, you might have to use quotes around arrays or other passed values. Use
--help to see examples for how to use the core functionality of this command.
Usage: sui client ptb [OPTIONS]
Options:
--assign <NAME> <VALUE>
Assign a value to a variable name to use later in the PTB.
--dry-run
Perform a dry run of the PTB instead of executing it.
--gas-coin <ID>
The object ID of the gas coin to use. If not specified, it will try to
use the first gas coin that it finds that has at least the requested
gas-budget balance.
--gas-budget <MIST>
An optional gas budget for this PTB (in MIST). If gas budget is not
provided, the tool will first perform a dry run to estimate the gas
cost, and then it will execute the transaction. Please note that this
incurs a small cost in performance due to the additional dry run call.
--make-move-vec <TYPE> <[VALUES]>
Given n-values of the same type, it constructs a vector. For non
objects or an empty vector, the type tag must be specified.
--merge-coins <INTO_COIN> <[COIN OBJECTS]>
Merge N coins into the provided coin.
--move-call <PACKAGE::MODULE::FUNCTION> <TYPE_ARGS> <FUNCTION_ARGS>
Make a move call to a function.
--split-coins <COIN> <[AMOUNT]>
Split the coin into N coins as per the given array of amounts.
--transfer-objects <[OBJECTS]> <TO>
Transfer objects to the specified address.
--publish <MOVE_PACKAGE_PATH>
Publish the Move package. It takes as input the folder where the
package exists.
--upgrade <MOVE_PACKAGE_PATH>
Upgrade the Move package. It takes as input the folder where the
package exists.
--preview
Preview the list of PTB transactions instead of executing them.
--serialize-unsigned-transaction
Instead of executing the transaction, serialize the bcs bytes of the
unsigned transaction data using base64 encoding.
--serialize-signed-transaction
Instead of executing the transaction, serialize the bcs bytes of the
signed transaction data using base64 encoding.
--summary
Show only a short summary (digest, execution status, gas cost). Do not
use this flag when you need all the transaction data and the execution
effects.
--warn-shadows
Enable shadow warning when the same variable name is declared multiple
times. Off by default.
(2) 命令使用
(a) 变量绑定(--assign
)
可以使用--assign
参数将值绑定到变量。
- 命令用法
--assign <NAME> <VALUE>
Assign a value to a variable name to use later in the PTB.
-
使用示例
-
用法1:为变量赋值
--assign value 1000
-
用法2:将上一个命令的结果绑定到变量
--split-coins gas [1000] \ --assign coin
-
(b) 地址和对象ID的表达(@
)
- 地址和对象
ID
前需要添加**@
**,以便和普通十六进制数值区分开 - 对于本地钱包中的地址,可以使用别名,不用添加
@
(c) 转移对象(--transfer-objects
)
可以使用--transfer-objects
参数转移对象。
- 命令用法
--transfer-objects <[OBJECTS]> <TO>
Transfer objects to the specified address.
- 使用示例
注:命令中
Coin
对象ID
和地址均需使用@
开头,以跟普通十六进制数值区分开
sui client ptb \
--assign coin @0x75794e86466c09edbe26a814c2e2f46a64f0391a05a7e9725dfad1bed2229b36 \
--transfer-objects [coin] @0x5c5882d73a6e5b6ea1743fb028eff5e0d7cc8b7ae123d27856c5fe666d91569a
(d) 拆分代币(--split-coins
)
使用--split-coins
参数可以拆分代币。
- 命令用法
--split-coins <COIN> <[AMOUNT]>
Split the coin into N coins as per the given array of amounts.
-
使用示例
-
从Gas中拆分
sui client ptb \ --split-coins gas [1000] \ --assign coins \ --transfer-objects [coins] jason
-
从Coin对象中拆分
sui client ptb \ --split-coins @0x1c8bbc2765028d99fbeba11caa5d7a7e13c110bbe0f4c9afb53c9f2f51cb897c [1000] \ --assign coins \ --transfer-objects [coins] jason
-
(e) 合并代币(--merge-coins
)
- 命令用法
--merge-coins <INTO_COIN> <[COIN OBJECTS]>
Merge N coins into the provided coin.
- 使用示例
sui client ptb \
--assign base_coin @0xe8d7bf9b843f4f4adc5962976f3e9afa677f431f9752ac4c3849b86a7798b20c\
--split-coins gas [1000, 2000, 3000] \
--assign coins \
--merge-coins base_coin [coins.0, coins.1, coins.2] \
--transfer-objects [coins] jason
- 执行前
- 执行后
(f) 交易预览(--preview
)
如果构造了复杂的PTB,可以使用--preview
参数来预览PTB交易执行列表而非执行它。
- 命令用法
--preview
Preview the list of PTB transactions instead of executing them.
- 使用示例
sui client ptb \
--assign value1 2024 \
--assign to_address1 jason \
--assign to_address2 @0x2d178b9704706393d2630fe6cf9415c2c50b181e9e3c7a977237bb2929f82d19 \
--split-coins gas [value1,4096,8848] \
--assign coins \
--transfer-objects [coins.0] to_address1 \
--transfer-objects [coins.1, coins.2] to_address2 \
--gas-budget 100000000 \
--preview
(g) 摘要展示(--summary
)
使用--summary
参数,可以进行简短的摘要展示,包括:交易哈希、执行状态、Gas
消耗。
- 命令用法
--summary
Show only a short summary (digest, execution status, gas cost). Do not use this flag when you need all the transaction data and the execution effects.
- 使用示例
sui client ptb \
--assign value1 2024 \
--assign to_address1 jason \
--assign to_address2 @0x2d178b9704706393d2630fe6cf9415c2c50b181e9e3c7a977237bb2929f82d19 \
--split-coins gas [value1,4096,8848] \
--assign coins \
--transfer-objects [coins.0] to_address1 \
--transfer-objects [coins.1, coins.2] to_address2 \
--gas-budget 100000000 \
--summary

(h) 试运行(dry-run
)
使用--dry-run
参数,可以试运行PTB
,输出执行信息,但非实际上链执行。
- 命令用法
--dry-run
Perform a dry run of the PTB instead of executing it.
- 使用示例
sui client ptb \
--assign value1 2024 \
--assign to_address1 jason \
--assign to_address2 @0x2d178b9704706393d2630fe6cf9415c2c50b181e9e3c7a977237bb2929f82d19 \
--split-coins gas [value1,4096,8848] \
--assign coins \
--transfer-objects [coins.0] to_address1 \
--transfer-objects [coins.1, coins.2] to_address2 \
--gas-budget 100000000 \
--dry-run
(i) 对象数组(--make-move-vec
)
使用--make-move-vec
参数,可以构造一个对象数组,可以在MoveCall
中使用。
- 命令用法
--make-move-vec <TYPE> <[VALUES]>
Given n-values of the same type, it constructs a vector. For non objects or an empty vector, the type tag must be specified.
- 使用示例
sui client ptb \
--make-move-vec "<u64>" [1111, 2222] \
--make-move-vec "<address>" [jason, @0x2d178b9704706393d2630fe6cf9415c2c50b181e9e3c7a977237bb2929f82d19]
(j) 方法调用(--move-call
)
使用--move-call
参数,可以调用合约中的方法。
- 命令用法
--move-call <PACKAGE::MODULE::FUNCTION> <TYPE> <FUNCTION_ARGS>
Make a move call to a function.
- 使用示例
以红包合约创建红包接口(
send_new_red_packet
)调用为例(详见:https://learnblockchain.cn/article/7772)。之前我们在命令行下,为了创建一个红包很繁琐的使用了多条命令,现在使用
PTB
只需要一条命令就能轻松搞定。
以下命令,将创建5个拼手气红包,总金额0.1 SUI
sui client ptb \
--assign PACKAGE_ID @0xe5417558cf7edc87840fef347f294dc0fa7bdcd82c043e630c504d233c6b4784 \
--assign COUNT 5 \
--assign AMOUNT 100000000 \
--split-coins gas [AMOUNT] \
--assign coins \
--move-call PACKAGE_ID::red_packet::send_new_red_packet "<0x2::sui::SUI>" COUNT coins.0
(k) 部署包(--publish
)
使用--publish
参数可以部署Move
包,和sui client publish
命令相比,sui client ptb --publish
命令必须显式的转移创建包成功后产生的UpgradeCap
对象。
- 命令用法
--publish <MOVE_PACKAGE_PATH>
Publish the Move package. It takes as input the folder where the package exists.
- 使用示例
sui client ptb \
--move-call sui::tx_context::sender \
--assign sender \
--publish "." \
--assign upgrade_cap \
--transfer-objects [upgrade_cap] sender \
3.8 调优类
3.8.1 profile-transaction
: 交易gas
消耗分析
(1) 命令说明
执行该命令,可以分析指定交易的gas
消耗情况。
注:要启用分析功能,需要编译
Sui
项目时指定--features gas-profiler
。$ cargo build --features gas-profiler --release
或者:
$ cargo install --locked --git https://github.com/MystenLabs/sui.git --branch <BRANCH-NAME> --features gas-profiler sui
Profile the gas usage of a transaction. Unless an output filepath is not specified, outputs a file
`gas_profile_{tx_digest}_{unix_timestamp}.json` which can be opened in a flamegraph tool such as speedscope
Usage: sui client profile-transaction [OPTIONS] --tx-digest <TX_DIGEST>
Options:
-t, --tx-digest <TX_DIGEST> The digest of the transaction to replay
-p, --profile-output <PROFILE_OUTPUT> If specified, overrides the filepath of the output profile, for example --
/temp/my_profile_name.json will write output to
`/temp/my_profile_name_{tx_digest}_{unix_timestamp}.json` If an output filepath is
not specified, it will output a file
`gas_profile_{tx_digest}_{unix_timestamp}.json` to the working directory
(2) 命令使用
$ sui client profile-transaction --tx-digest 6yE93gtnBzyq9XAtKiJ6bQwrs91B6vVRuK4QucRjKhY9
INFO sui_replay: Executing tx: 6yE93gtnBzyq9XAtKiJ6bQwrs91B6vVRuK4QucRjKhY9
INFO sui_replay::replay: Using RPC URL: https://fullnode.devnet.sui.io:443
INFO move_vm_profiler: Gas profile written to file: ./gas_profile.json_6yE93gtnBzyq9XAtKiJ6bQwrs91B6vVRuK4QucRjKhY9_1720628540191496861.json
Execution finished successfully.
命令成功之后后,会输出分析结构到json文件中,这个文件可以在类似speedscope
的火焰图工具中打开,以便对交易gas
使用情况进行可视化分析。
3.8.2 replay-transaction
: 给定交易重放
(1) 命令说明
执行该命令可以重放指定交易,并查看交易执行效果。
Replay a given transaction to view transaction effects. Set environment variable
MOVE_VM_STEP=1 to debug
Usage: sui client replay-transaction [OPTIONS] --tx-digest <TX_DIGEST>
Options:
-t, --tx-digest <TX_DIGEST>
The digest of the transaction to replay
--gas-info
Log extra gas-related information
--ptb-info
Log information about each programmable transaction command
-e, --executor-version <EXECUTOR_VERSION>
Optional version of the executor to use, if not specified defaults to
the one originally used for the transaction
-p, --protocol-version <PROTOCOL_VERSION>
Optional protocol version to use, if not specified defaults to the one
originally used for the transaction
(2) 命令使用
INFO sui_replay: Executing tx: 6yE93gtnBzyq9XAtKiJ6bQwrs91B6vVRuK4QucRjKhY9
INFO sui_replay::replay: Using RPC URL: https://fullnode.devnet.sui.io:443
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Transaction Effects │
├───────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Digest: 6yE93gtnBzyq9XAtKiJ6bQwrs91B6vVRuK4QucRjKhY9 │
│ Status: Success │
│ Executed Epoch: 58 │
│ │
│ Created Objects: │
│ ┌── │
│ │ ID: 0x91ed399242d4b0424280385af7c890477521c469e1e51deada8f8b29876b27bc │
│ │ Owner: Shared( 7 ) │
│ │ Version: 7 │
│ │ Digest: 9XrVCsYjKMXK6dFiRRQLoCTVvS1B5KUJfW9kGrZGADkR │
│ └── │
│ ┌── │
│ │ ID: 0xb9e8c31d1557825b8a93ad695213056a7595e6e546f21b10f794670754375e45 │
│ │ Owner: Account Address ( 0x5c5882d73a6e5b6ea1743fb028eff5e0d7cc8b7ae123d27856c5fe666d91569a ) │
│ │ Version: 7 │
│ │ Digest: CvmwZCtRYqA7hk2qQ4sfWPiqsBaKVqReMbihe8UNFMrD │
│ └── │
│ ┌── │
│ │ ID: 0xc94b31119ae9ab32fb6d72385b5611cfbfcb08a9ba673558345044fd493b202d │
│ │ Owner: Immutable │
│ │ Version: 1 │
│ │ Digest: EM7NCDMp1MYaF9N2tKqUb1sA1BF1pDgp3sNaQqGrybHS │
│ └── │
│ Mutated Objects: │
│ ┌── │
│ │ ID: 0x07904d4deba1a822d52a674205548b36b28859620282479144454d3c096ffa15 │
│ │ Owner: Account Address ( 0x5c5882d73a6e5b6ea1743fb028eff5e0d7cc8b7ae123d27856c5fe666d91569a ) │
│ │ Version: 7 │
│ │ Digest: DGGDwDw6xdJFiLQGEyCxoFh8wh1WcZvUCaetG7uxwUYF │
│ └── │
│ Gas Object: │
│ ┌── │
│ │ ID: 0x07904d4deba1a822d52a674205548b36b28859620282479144454d3c096ffa15 │
│ │ Owner: Account Address ( 0x5c5882d73a6e5b6ea1743fb028eff5e0d7cc8b7ae123d27856c5fe666d91569a ) │
│ │ Version: 7 │
│ │ Digest: DGGDwDw6xdJFiLQGEyCxoFh8wh1WcZvUCaetG7uxwUYF │
│ └── │
│ Gas Cost Summary: │
│ Storage Cost: 15967600 MIST │
│ Computation Cost: 1000000 MIST │
│ Storage Rebate: 978120 MIST │
│ Non-refundable Storage Fee: 9880 MIST │
│ │
│ Transaction Dependencies: │
│ DeqpG2KUFuu3Rkf6rwKaGeYSjwxM1x9r6HqWKeGaqnQZ │
│ FMmtZmZ6S5oNVUeUuNwvB3fGH44ekyxzzywfSBuHvtjn │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
Execution finished successfully. Local and on-chain effects match.
3.8.3 replay-batch
: 批量交易重放
(1) 命令说明
执行该命令可以批量重放指定文件中的交易,并查看交易执行效果。
Replay transactions listed in a file
Usage: sui client replay-batch [OPTIONS] --path <PATH>
Options:
-p, --path <PATH> The path to the file of transaction digests to replay,
with one digest per line
-t, --terminate-early If an error is encountered during a transaction, this
specifies whether to terminate or continue
(2) 命令使用
$ sui client replay-batch --path ./txs.txt
INFO sui_replay::batch_replay: [1/3] Replaying transaction TransactionDigest(6yE93gtnBzyq9XAtKiJ6bQwrs91B6vVRuK4QucRjKhY9)...
INFO sui_replay::batch_replay: [2/3] Replaying transaction TransactionDigest(EME9x9B8iWHhpUa3BpEKkYgmq1P18jUgC9hQN89kWkxP)...
INFO sui_replay::batch_replay: [3/3] Replaying transaction TransactionDigest(zKFQ9qrHVFHcoJnxcYmUCCHhfDv1uwwzzgEErmAKo7z)...
INFO sui_replay::batch_replay: Replaying transaction TransactionDigest(EME9x9B8iWHhpUa3BpEKkYgmq1P18jUgC9hQN89kWkxP) succeeded
INFO sui_replay::batch_replay: Replaying transaction TransactionDigest(6yE93gtnBzyq9XAtKiJ6bQwrs91B6vVRuK4QucRjKhY9) succeeded
INFO sui_replay::batch_replay: Replaying transaction TransactionDigest(zKFQ9qrHVFHcoJnxcYmUCCHhfDv1uwwzzgEErmAKo7z) succeeded
INFO sui_replay::batch_replay: Finished replaying 3 transactions, took 1.957193059s
INFO sui_replay::batch_replay: All transactions passed
3.8.4 replay-checkpoint
: 重放指定一段检查点区间内的所有交易
(1) 命令说明
执行该命令可以重放指定一段检查点区间内的所有交易,并查看交易执行效果。
检查点(checkpoint
)类似传统区块链的区块。
Replay all transactions in a range of checkpoints
Usage: sui client replay-checkpoint [OPTIONS] --start <START> --end <END>
Options:
-s, --start <START> The starting checkpoint sequence number of the range
of checkpoints to replay
-e, --end <END> The ending checkpoint sequence number of the range of
checkpoints to replay
-t, --terminate-early If an error is encountered during a transaction, this
specifies whether to terminate or continue
(2) 命令使用
$ sui client replay-checkpoint --start 87468287 --end 87468289