sui-cli使用指南

  • gracecampo
  • 更新于 2024-11-16 21:08
  • 阅读 474

Sui CLI 命令提供与 Sui 网络交互的终端命令入口。典型用途包括发布 Move 智能合约、获取对象信息、执行事务或管理地址。

sui-cli使用指南

🧑‍💻作者:gracecampo

sui cli 介绍

Sui CLI 命令提供与 Sui 网络交互的终端命令入口。典型用途包括发布 Move 智能合约、获取对象信息、执行事务或管理地址。

检查sui cli 安装及版本

使用sui cli 之前,必须检查是否已经安装成功,可以在终端窗口输入一下命令

sui --version

如果未安装,可参考之前文章:如何安装sui

查看sui cli 支持的命令列表

sui client

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)

Options:
--client.config <CONFIG>  Sets the file storing the state of our user accounts (an empty one will be created if missing)
--json                    Return command outputs in json format
-y, --yes
-h, --help                    Print help

地址管理

地址相关命令

sui client addresses  --查看地址列表

sui client active-address   --查看当前地址

sui client new-address ed25519  --创建地址

sui client new-address ed25519 MY_ALIAS --自定义地址别名

sui client switch --address ADDRESS   --切换地址,也支持别名切换

sui keytool list  --获取地址详细信息

sui keytool generate ed25519   --生成地址

sui keytool update-alias  <OLD_ALIAS> [NEW_ALIAS]  --修改地址别名

sui keytool import     --导入地址

sui keytool  export --key-identity    --导出地址

查看地址列表

sui client addresses

╭─────────────────────┬────────────────────────────────────────────────────────────────────┬────────────────╮
│ alias               │ address                                                            │ active address │
├─────────────────────┼────────────────────────────────────────────────────────────────────┼────────────────┤
│ quizzical-corundum  │ 0x6a7e12ee188658b7fb62d00b897143808e6a54e6185843dedb54eb70e70e3efe │ *              │
│ vigilant-quartz     │ 0xb76dbc0cab651095651eb550a522d450ab2a1c267ddc5ea70a263fe5b51a6013 │                │
│ pensive-chrysoberyl │ 0xc33c26e95d20423c2a4a9179ae59e845712f01682ac6bcbccf39f0f8542e6cdd │                │
╰─────────────────────┴────────────────────────────────────────────────────────────────────┴────────────────╯

查看当前地址 sui client active-address

0x6a7e12ee188658b7fb62d00b897143808e6a54e6185843dedb54eb70e70e3efe

生成地址 sui client new-address ed25519

╭────────────────────────────────────────────────────────────────────────────────────────────╮
│ Created new keypair and saved it to keystore.                                              │
├────────────────┬───────────────────────────────────────────────────────────────────────────┤
│ alias          │ elastic-topaz                                                             │
│ address        │ 0x9ae8ca9263455c1a1d9243ebc5986496bb315b1c3343f1100851e218e7575348        │
│ keyScheme      │ ed25519                                                                   │
│ recoveryPhrase │ ready west frame ability drop valve quick snake bargain render ghost know │
╰────────────────┴───────────────────────────────────────────────────────────────────────────╯

生成地址并起别名 sui client new-address ed25519 MY_ALIAS

╭─────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Created new keypair and saved it to keystore.                                                   │
├────────────────┬────────────────────────────────────────────────────────────────────────────────┤
│ alias          │ alice                                                                          │
│ address        │ 0x7307b3e2f4082027d8b59abeced019d3910346b50369af62e8b938573ec517ef             │
│ keyScheme      │ ed25519                                                                        │
│ recoveryPhrase │ version write opinion reject title isolate guard beef glare short they citizen │
╰────────────────┴────────────────────────────────────────────────────────────────────────────────╯

切换当前活跃地址 sui client switch --address ADDRESS

Active address switched to 0x7307b3e2f4082027d8b59abeced019d3910346b50369af62e8b938573ec517ef

生成地址 sui keytool generate ed25519

╭─────────────────┬───────────────────────────────────────────────────────────────────────────╮
│ alias           │                                                                           │
│ suiAddress      │  0x5a684e30c7760309906a4ed7b25e2d0c4bbeff74a3995a8ccbfe49be084d16d0       │
│ publicBase64Key │  AIxbJxtY8vmqLYKfTE/rbPVXX95Gw/MIIDPOTgHW8+QI                             │
│ keyScheme       │  ed25519                                                                  │
│ flag            │  0                                                                        │
│ mnemonic        │  immune camera soft miss panther couple remove egg joy wasp genre burger  │
│ peerId          │  8c5b271b58f2f9aa2d829f4c4feb6cf5575fde46c3f3082033ce4e01d6f3e408         │
╰─────────────────┴───────────────────────────────────────────────────────────────────────────╯

导出地址 sui keytool export --key-identity

╭────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────╮
│ exportedPrivateKey │  suiprivkey1qr2dw8m9wsuu5tglswckdzugjf2m358thz555nqy4gy8xarjnwxgwymjxp6                    │
│ key                │ ╭─────────────────┬──────────────────────────────────────────────────────────────────────╮ │
│                    │ │ alias           │                                                                      │ │
│                    │ │ suiAddress      │  0xc33c26e95d20423c2a4a9179ae59e845712f01682ac6bcbccf39f0f8542e6cdd  │ │
│                    │ │ publicBase64Key │  AC+R965NvHH13JnhnIEPqsvQC7xd5wRokWfZyTPTFS9a                        │ │
│                    │ │ keyScheme       │  ed25519                                                             │ │
│                    │ │ flag            │  0                                                                   │ │
│                    │ │ peerId          │  2f91f7ae4dbc71f5dc99e19c810faacbd00bbc5de704689167d9c933d3152f5a    │ │
│                    │ ╰─────────────────┴──────────────────────────────────────────────────────────────────────╯ │
╰────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────╯

导入地址 sui keytool import <INPUT_STRING> <KEY_SCHEME> [DERIVATION_PATH]

╭─────────────────┬──────────────────────────────────────────────────────────────────────╮
│ alias           │  wangwu                                                              │
│ suiAddress      │  0x5a684e30c7760309906a4ed7b25e2d0c4bbeff74a3995a8ccbfe49be084d16d0  │
│ publicBase64Key │  AIxbJxtY8vmqLYKfTE/rbPVXX95Gw/MIIDPOTgHW8+QI                        │
│ keyScheme       │  ed25519                                                             │
│ flag            │  0                                                                   │
│ peerId          │  8c5b271b58f2f9aa2d829f4c4feb6cf5575fde46c3f3082033ce4e01d6f3e408    │
╰─────────────────┴──────────────────────────────────────────────────────────────────────╯

测试代币获取

获取测试代币命令


sui client faucet  --通过水龙头获取测试代币

sui client faucet --address ADDRESS --指定地址通过水龙头获取测试代币

sui client faucet --url CUSTOM_FAUCET_URL ----指定水龙头URL地址获取测试代币

sui client gas ----获取当前地址测试代币余额

sui client gas ADDRESS ----获取指定地址测试代币余额

>通过水龙头获取测试gas代币
>> sui client faucet
```text
Request successful. It can take up to 1 minute to get the coin. Run sui client gas to check your gas coins.

为指定地址获取测试gas代币

sui client faucet --address ADDRESS

Request successful. It can take up to 1 minute to get the coin. Run sui client gas to check your gas coins.

查看地址gas余额 sui client gas

╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId                                                          │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0xd46fd2a39983be3d9d9769c768c49ef2a16e8b36c20c28aa0634bf0d588ef7d1 │ 1000000000         │ 1.00             │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯

查看指定地址代币 sui client gas ADDRESS

╭────────────────────────────────────────────────────────────────────┬────────────────────┬──────────────────╮
│ gasCoinId                                                          │ mistBalance (MIST) │ suiBalance (SUI) │
├────────────────────────────────────────────────────────────────────┼────────────────────┼──────────────────┤
│ 0x0677e401bae703cddbc0332d7098e9ac78e353984ca118f1705dbc97a67a9871 │ 1000000000         │ 1.00             │
╰────────────────────────────────────────────────────────────────────┴────────────────────┴──────────────────╯

环境管理

环境相关命令


sui client active-env  --获取当前的环境地址

sui client envs --获取环境地址列表

sui client new-env --rpc URL --alias ALIAS --添加自定义地址

sui client switch --env ENV_ALIAS --切换当前环境

>获取当前的环境地址
> sui client active-env
```text
 testnet

获取环境地址列表

sui client envs

╭─────────┬─────────────────────────────────────┬────────╮
│ alias   │ url                                 │ active │
├─────────┼─────────────────────────────────────┼────────┤
│ testnet │ https://fullnode.testnet.sui.io:443 │ *      │
│ mainnet │ https://fullnode.mainnet.sui.io:443 │        │
│ devnet  │ https://fullnode.devnet.sui.io:443  │        │
╰─────────┴─────────────────────────────────────┴────────╯

添加自定义地址 sui client new-env --rpc URL --alias ALIAS

Added new Sui env [devnet] to config.

切换当前环境 sui client switch --env ENV_ALIAS

Active environment switched to [mainnet]

创建、构建和测试 Move 项目


sui move new PROJECT_NAME   在给定文件夹中创建新的 Move 项目

sui move build 在当前目录中构建 Move 项目

sui move build --path PATH 从给定路径构建 Move 项目

sui move test 在当前目录中测试 Move 项目

> 创建新的 Move 项目
>> sui move new PROJECT_NAME
```text
创建完成,会在当前目录创建一个项目脚手架,通过ide打开

构建 Move 项目

sui move build

PS F:\project\move-project\task3> sui move build
UPDATING GIT DEPENDENCY https://gitee.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING task3

从给定路径构建 Move 项目 sui move build --path PATH

PS F:\project\move-project> sui move build --path .\task4\
UPDATING GIT DEPENDENCY https://gitee.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING task4

测试 Move 项目 sui move test

PS F:\project\move-project\task3> sui move test
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING task3
Running Move unit tests
Test result: OK. Total tests: 0; passed: 0; failed: 0

执行事务


sui client publish  --发布模块

sui client call --package PACKAGE --module MODULE --function FUNCTION --调用 Move 包

sui client merge-coin --primary-coin COIN_ID --coin-to-merge COIN_ID --合并两个硬币

sui client split-coin --coin-id COIN_ID --amounts 1000 --将硬币拆分为两个硬币:一个具有 1000 MIST,其余的

sui client pay-sui --input-coins COIN_ID --recipients ADDRESS --amounts 100000000 --将 0.1 SUI 转入地址,并使用相同的币种支付 gas

sui client transfer-sui --sui-coin-object-id COIN_ID --to ADDRESS --将 SUI 对象转移到一个地址,并使用相同的币种进行 gas


>铸造代币
>> sui client call --package 0xf3208487e8bd1e553381aed09a6441ddbeeb5143f72f9c6f28d0249be98e54ce --module mycoin --function mint --args 0x55ed4bda886190b733c00547c355130e7282b33aece85e11a0dabd3642dfa258 100000000 0x6a7e12ee188658b7fb62d00b897143808e6a54e6185843dedb54eb70e70e3efe

> 合并其他代币可以使用
>> sui client merge-coin --primary-coin 0xa2f6d4e377bccace0d74ee77cd3f6eec73be532f7abbede2306e170f1ff02742 --coin-to-merge 0xd8aa70129bf17501610418c83213710e26c03bd03c3e65b14a97a9269b23687f

> 拆分将硬币拆分为两个代币
> > sui client split-coin --coin-id 0xa2f6d4e377bccace0d74ee77cd3f6eec73be532f7abbede2306e170f1ff02742 --amounts 100000000

> 将  SUI 转入地址
>> sui client pay-sui --input-coins 0x18cae58f01b1d7e7dcefd486f64c8f5fe46fd46e0d3f6e8b61175a433b8be499  --recipients 0x7307b3e2f4082027d8b59abeced019d3910346b50369af62e8b938573ec517ef --amounts 100000000 --gas-budget 100000000

> 将 SUI 对象转移到一个地址
> >sui client transfer-sui --sui-coin-object-id 0x285e6e649c360be278eab0778163411165a506fb062114d03273c5cecd33c934 --to 0x6a7e12ee188658b7fb62d00b897143808e6a54e6185843dedb54eb70e70e3efe --gas-budget 100000000

💧  [HOH水分子公众号](https://mp.weixin.qq.com/s/d0brr-ao6cZ5t8Z5OO1Mog)

🌊  [HOH水分子X账号](https://x.com/0xHOH)

📹  [课程B站账号](https://space.bilibili.com/3493269495352098)

💻  Github仓库 https://github.com/move-cn/letsmove
点赞 0
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论
gracecampo
gracecampo
0xf349...8BF9
江湖只有他的大名,没有他的介绍。