开发
参考指南
Rooch CLI

Rooch CLI

了解如何设置、配置和使用 Rooch 命令行界面(CLI)。您可以通过 Rooch CLI 来试验 Rooch 的特性。

安装

安装 Rooch 时,将安装 Rooch CLI。有关先决条件和安装说明,请参阅安装主题。

Rooch CLI 支持以下命令:

[joe@mx rooch]$ rooch --help
 
Usage: rooch <COMMAND>
 
Commands:
  account      Tool for interacting with accounts
  init         Tool for init with rooch
  move         CLI frontend for the Move compiler and VM
  server       Start Rooch network
  state        Get states by accessPath
  object       Get object by object id
  resource     Get account resource by tag
  transaction  Tool for interacting with transaction
  event        Tool for interacting with event
  abi
  env          Interface for managing multiple environments
  session-key  Session key Commands
  rpc
  help         Print this message or the help of the given subcommand(s)
 
Options:
  -h, --help     Print help
  -V, --version  Print version

使用 rooch -h 来查看支持的命令列表。

使用 rooch help <COMMAND> 来查看指定命令的更多信息。

初始化 Rooch 配置

默认情况下,Rooch 的配置文件保存在您的 home 目录。

使用 rooch init 来初始化 Rooch 账户,配置文件的位置通过 --config-dir 指定。

响应类似于以下内容:

[joe@mx rooch]$ rooch init
 
Rooch server config file generated at /home/joe/.rooch/rooch_config/server.yaml
Creating client config file ["/home/joe/.rooch/rooch_config/rooch.yaml"] with rooch native validator.
Enter a password to encrypt the keys. Press enter to leave it an empty password:
Generated new keypair for address [0x270b27b9bb269adc0e8ed45ae19fec12d4b9f913e59bc394284c342b43e88d28]
Secret Recovery Phrase : [student cute patrol habit garage suffer eye aunt biology frost tuna sentence]
Rooch client config file generated at /home/joe/.rooch/rooch_config/rooch.yaml
null

提示:在提示设置加码密钥的密码时,如果直接回车,表示不设置密码!

更多示例

账户管理

可以使用这个命令来创建新账户,列出当前管理的所有账户,切换账户,删除账户,查看账户余额。

[joe@mx rooch]$ rooch account
 
Tool for interacting with accounts
 
Usage: rooch account [OPTIONS] <COMMAND>
 
Commands:
  create   Create a new account off-chain. If an account not exist on-chain, contract will auto create the account on-chain
  list     List all keys by its Rooch address, Base64 encoded public key
  switch   Switch the active Rooch account
  nullify  Nullify a keypair from a selected coin id with a Rooch address in rooch.keystore
  balance  Show account balance, only the accounts managed by the current node are supported
  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)
  -h, --help                    Print help

Move 客户端

操作 Move 编译器和 Move 虚拟机的客户端程序。

[joe@mx rooch]$ rooch help move
 
CLI frontend for the Move compiler and VM
 
Usage: rooch move [OPTIONS] <COMMAND>
 
Commands:
  build              Build the package at `path`. If no path is provided defaults to current directory
  coverage           Inspect test coverage for this package. A previous test run with the `--coverage` flag must have previously been run
  disassemble        Disassemble the Move bytecode pointed to
  docgen             Generate javadoc style documentation for Move packages
  errmap             Generate error map for the package and its dependencies at `path` for use by the Move explanation tool
  info               Print address information
  new
  prove              Run the Move Prover on the package at `path`. If no path is provided defaults to current directory. Use `.. prove .. -- <options>` to pass on options to the prover
  test               Run Move unit tests in this package
  publish            Common options for interacting with an account for a validator
  run                Run a Move function
  view               Run a Move function
  integration-test   Integration test
  explain            Explain Move abort codes. Errors are defined as a global category + module-specific reason for the error
  framework-upgrade  Common options for interacting with an account for a validator
  help               Print this message or the help of the given subcommand(s)
 
Options:
  -p, --path <PACKAGE_PATH>
          Path to a package which the command should be run with respect to
  -v
          Print additional diagnostics if available
  -d, --dev
          Compile in 'dev' mode. The 'dev-addresses' and 'dev-dependencies' fields will be used if this flag is set. This flag is useful for development of packages that expose named addresses that are not set to a specific value
      --test
          Compile in 'test' mode. The 'dev-addresses' and 'dev-dependencies' fields will be used along with any code in the 'tests' directory
      --doc
          Generate documentation for packages
      --abi
          Generate ABIs for packages
      --install-dir <INSTALL_DIR>
          Installation directory for compiled artifacts. Defaults to current directory
      --force
          Force recompilation of all packages
      --arch <ARCHITECTURE>
 
      --fetch-deps-only
          Only fetch dependency repos to MOVE_HOME
      --skip-fetch-latest-git-deps
          Skip fetching latest git dependencies
      --bytecode-version <BYTECODE_VERSION>
          Bytecode version to compile move code
  -h, --help
          Print help
  -V, --version
          Print version

本地网络服务

在本地启动一个服务节点模拟链的服务,通常用于本地测试,提供启动和清理本地数据的命令。

[joe@mx rooch]$ rooch server
 
Start Rooch network
 
Usage: rooch server <COMMAND>
 
Commands:
  start  Start service
  clean  Clean the Rooch server storage
  help   Print this message or the help of the given subcommand(s)
 
Options:
  -h, --help  Print help

使用 rooch server start 来启动一个本地服务。

重要提示:每次启动 Rooch 服务器时,该网络都作为一个新网络启动,没有以前的数据。

响应类似于以下内容:

Documentation generation successful!
2023-07-17T05:34:49.963869Z  INFO rooch_rpc_server: JSON-RPC HTTP Server start listening 0.0.0.0:6767
2023-07-17T05:34:49.963893Z  INFO rooch_rpc_server: Available JSON-RPC methods : ["wallet_accounts", "eth_blockNumber", "eth_getBalance", "eth_gasPrice", "net_version", "eth_getTransactionCount", "eth_sendTransaction", "rooch_sendRawTransaction", "rooch_getAnnotatedStates", "eth_sendRawTransaction", "rooch_getTransactions", "rooch_executeRawTransaction", "rooch_getEventsByEventHandle", "rooch_getTransactionByHash", "rooch_executeViewFunction", "eth_getBlockByNumber", "rooch_getEvents", "eth_feeHistory", "eth_getTransactionByHash", "eth_getBlockByHash", "eth_getTransactionReceipt", "rooch_getTransactionInfosByTxOrder", "eth_estimateGas", "eth_chainId", "rooch_getTransactionInfosByTxHash", "wallet_sign", "rooch_getStates"]

状态查询

通过 Access Path 来查询对象的状态信息。

[joe@mx rooch]$ rooch help state
 
Get states by accessPath
 
Usage: rooch state [OPTIONS] --access-path <ACCESS_PATH>
 
Options:
  -a, --access-path <ACCESS_PATH>  /object/$object_id1[,$object_id2] /resource/$account_address/$resource_type1[,$resource_type2] /module/$account_address/$module_name1[,$module_name2] /table/$table_handle/$key1[,$key2]
      --config-dir <CONFIG_DIR>    rooch config path
  -h, --help                       Print help

对象查询

通过对象 ID 来查询对象的信息。

[joe@mx rooch]$ rooch help object
 
Get object by object id
 
Usage: rooch object [OPTIONS] --id <ID>
 
Options:
      --id <ID>                  Object id
      --config-dir <CONFIG_DIR>  rooch config path
      --show-display
  -h, --help                     Print help

资源查询

通过 --resource 选项来指定查询资源的类型。

[joe@mx rooch]$ rooch help resource
 
Get account resource by tag
 
Usage: rooch resource [OPTIONS] --address <ADDRESS> --resource <RESOURCE>
 
Options:
      --address <ADDRESS>        Account address where the resource stored
      --resource <RESOURCE>      Struct name as `<ADDRESS>::<MODULE_ID>::<STRUCT_NAME><TypeParam1?, TypeParam2?>` Example: `0x123::counter::Counter`, `0x123::counter::Box<0x123::counter::Counter>`
      --config-dir <CONFIG_DIR>  rooch config path
  -h, --help                     Print help

交易查询

目前可以通过交易顺序或者交易哈希来查询交易信息。

[joe@mx rooch]$ rooch help transaction
 
Tool for interacting with transaction
 
Usage: rooch transaction <COMMAND>
 
Commands:
  get-transactions-by-order  Get transactions by order
  get-transactions-by-hash   Get transactions by hashes
  help                       Print this message or the help of the given subcommand(s)
 
Options:
  -h, --help  Print help

事件查询

通过指定事件句柄来查询相关的事件信息。

[joe@mx rooch]$ rooch help event
 
Tool for interacting with event
 
Usage: rooch event <COMMAND>
 
Commands:
  get-events-by-event-handle  Retrieves events based on their event handle
  help                        Print this message or the help of the given subcommand(s)
 
Options:
  -h, --help  Print help

Rooch ABI

[joe@mx rooch]$ rooch help abi
Usage: rooch abi [OPTIONS] <COMMAND>
 
Commands:
  export-rooch-types
  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)
  -h, --help                    Print help

网络管理

可以使用这个命令来管理网络环境,包括:添加网络,列出当前客户端存在的网络,切换网络,删除网络。

[joe@mx rooch]$ rooch help env
 
Interface for managing multiple environments
 
Usage: rooch env [OPTIONS] <COMMAND>
 
Commands:
  add     Add a new Rooch environment
  list
  switch
  remove
  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)
  -h, --help                    Print help

Session key

可以使用这个命令来创建 Session key。

[joe@mx rooch]$ rooch help session-key
 
Session key Commands
 
Usage: rooch session-key <COMMAND>
 
Commands:
  create  Create a new session key on-chain
  help    Print this message or the help of the given subcommand(s)
 
Options:
  -h, --help  Print help

Rooch RPC

这个命令用来发送 RPC 请求。

[joe@mx rooch]$ rooch help rpc
 
Usage: rooch rpc <COMMAND>
 
Commands:
  request  Send a RPC request
  help     Print this message or the help of the given subcommand(s)
 
Options:
  -h, --help  Print help