Build
Reference
Rooch CLI

Rooch CLI

Learn how to set up, configure, and use the Rooch command line interface (CLI). You can experiment with Rooch features through the Rooch CLI.

Installation

When you install Rooch, the Rooch CLI is installed. See the installation topic for prerequisites and installation instructions.

Rooch CLI supports the following commands:

[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

Use rooch -h to see a list of supported commands.

Use rooch help <COMMAND> to see more information about a specified command.

Initialize Rooch configuration

By default, Rooch's configuration files are saved in your home directory.

Use rooch init to initialize the Rooch account, and the location of the configuration file is specified with --config-dir.

The response is similar to the following:

[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

Tip: When prompted to set the password for the encryption key, if you press Enter directly, it means no password is set!

More examples

Account management

You can use this command to create new accounts, list all currently managed accounts, switch accounts, delete accounts, and view account balances.

[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 client

Client programs that operate the Move compiler and Move virtual machine.

[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

Local network service

Start a service node simulation chain service locally, usually used for local testing, and provide commands for starting and cleaning local data.

[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

Use rooch server start to start a local service.

IMPORTANT: Every time you start a Rooch server, the network starts as a new network without previous data.

The response is similar to the following:

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"]

Status query

Query the status information of the object through 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

Object query

Query object information by object 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 query

Specify the type of query resource through the --resource option.

[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

Transaction inquiry

Currently, transaction information can be queried through transaction sequence or transaction hash.

[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

Event query

Query related event information by specifying an event handle.

[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

Network management

You can use this command to manage the network environment, including: adding networks, listing the networks that currently exist on the client, switching networks, and deleting networks.

[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

You can use this command to create a 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

This command is used to send RPC requests.

[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