Skip to main content

CLI Usage

Need to Install CLI?

If you're looking for installation instructions, check our Getting Started CLI guide for step-by-step installation and setup.

๐Ÿ“– Overviewโ€‹

The Cedra Command Line Interface (CLI) is a developer tool for compiling and testing Move smart contracts, managing accounts, and interacting with the Cedra blockchain. It offers a convenient way to perform on-chain operations, run a local network, and manage keys directly from your terminal. This guide provides a feature-by-feature walkthrough of Cedra CLI usage, targeted at developers (including those new to Move and Cedra). Each section below explains what a feature does, when to use it, and provides step-by-step instructions with examples.

โšก Ready to start!โ€‹

These commands cover the typical development workflow:

Quick Commands
  • Use cedra init to initialize account ๐Ÿ—๏ธ
  • Use cedra move init when starting a new smart contract project ๐Ÿ“ฆ
  • Use compile and test frequently during development to catch errors and verify logic off-chain ๐Ÿ”
  • Use cedra move publish when you're ready to deploy your module to a network ๐Ÿš€

Want to dive deeper? Welcome to information below ๐Ÿ‘‡

1. Initial Configuration:โ€‹

After installing, configure the CLI and create an initial account profile using cedra init. This command creates a configuration file and can generate a new account for you.

  • Running cedra init: Open a terminal in your project or working folder and run:

    cedra init

    You will be prompted to enter:

    1. ๐ŸŒ REST URL โ€“ the endpoint of the Cedra fullnode to use. If you press Enter with no input, it defaults to Cedra Testnet's URL (e.g. https://testnet.cedra.dev).
    2. ๐Ÿ”‘ Private Key โ€“ a hex literal for your account's private key. If you leave this blank, the CLI will generate a new key pair for you automatically.

    For example, a new developer can accept all defaults to connect to Testnet and generate keys. The CLI then creates a fresh Cedra account on Testnet and funds it with test coins via the faucet. You'll see output similar to:

    Cedra is now set up for account 0x00f1f20...79696!  Run `cedra help` for more commands  
    {
    "Result": "Success"
    }

    This indicates a new account was created (with a unique address). The CLI saved your config in .cedra/config.yaml, which includes the active profile (named "default") and a reference to your new private key.

Multiple Profiles

Profiles: Cedra CLI supports multiple profiles, which are separate configurations (useful if you manage multiple accounts or networks). You can create additional profiles by running cedra init --profile <name> (e.g. cedra init --profile testProfile). This will prompt for endpoints and keys again and create a separate entry in your config file. Later, you can use --profile <name> flag with most commands to switch which account or network you are targeting. If no profile is specified, the CLI uses the default profile.

After initialization, you're ready to use Cedra CLI. In the following sections, we'll walk through common tasks like managing accounts, keys, Move packages, and more.

2. Account Managementโ€‹

In Cedra, an account represents an on-chain identity with an address, public/private key pair, and associated resources. The CLI provides commands to create accounts, fund them with test tokens, check their state, and perform basic transactions. This section covers how to manage accounts using Cedra CLI.

๐Ÿ†• Create a New Accountโ€‹

The simplest way to create a new account is via cedra init (as shown above), which generates a key and registers the account on Testnet automatically. You can also generate an account without the interactive prompt by using the key tool (see Key Management below) and then fund it manually.

๐Ÿ“Š Viewing Account Informationโ€‹

You can check its on-chain data using CLI queries. The cedra account list command lets you view balances, resources, and other details of an account.

  • ๐Ÿ’ฐ Check Balance: Every account has a balance of the native token (for Cedra Testnet, test CED or similar). To view an account's coin balance and related information, run:

    cedra account list --query balance --account default

    This will output JSON data like:

    {
    "Result": [
    {
    "coin": {
    "value": "110000"
    }
    ...
    }
    ]
    }

    The value field shows the account balance in the octas.

  • List Resources: An account can hold various Move resources (data structures defined by smart contracts). To list all resources in an account, use:

    cedra account list --account <ADDRESS>

    or equivalently --query resources. This returns all resources stored under that account in JSON format. For example, you will see the coin resource (as shown above), and any other resources the account has acquired (such as tokens, NFTs, etc.). Each resource is identified by its type (module and struct name) and contains the stored data.

  • List Modules: If the account has published Move modules (smart contracts), you can list them with:

    cedra account list --query modules --account <ADDRESS>

    This will output the bytecode for each module published in that account. (It's usually more useful to verify modules via source code, but this command confirms what's on-chain.)

  • Account Summary: Simply running cedra account list with no --query will default to listing resources (same as --query resources). This gives a quick snapshot of an account's state.

๐Ÿ’ธ Transferring Tokens Between Accountsโ€‹

Cedra CLI can act as a basic wallet to send the native coins from one account to another. The cedra account transfer command facilitates this.

  • ๐Ÿ“ค Send a Transfer: To send funds from your current profile's account to another account, run:

    cedra account transfer --account <RECIPIENT> --amount <NUMBER>

    This would transfer NUMBER coins from the default profile's account to the account associated with the "secondary" profile. The CLI will output a JSON result of the transaction, including the gas used, balance changes for both sender and receiver, and a success indicator:

    {
    "Result": {
    ...
    "vm_status": "Executed successfully"
    }
    }

3. Key Management (Generate & Recover Keys)โ€‹

Cedra CLI provides tools for generating new cryptographic keys, managing multiple keys, and importing existing keys from other wallets. This is useful for creating accounts programmatically or managing multiple development identities.

๐ŸŽฒ Generating New Keysโ€‹

  • Create Keys: The cedra key generate command creates a new Ed25519 key pair and saves it to files:

    cedra key generate --key-type ed25519 --output-file my-key

    This creates two files: my-key (private key) and my-key.pub (public key). The CLI will also print the account address that corresponds to this key:

    {
    "Result": {
    "PrivateKey Path": "my-key",
    "PublicKey Path": "my-key.pub"
    }
    }

    You can now use this key to initialize or import an account.

Key Security

Storing Keys: Keys generated with cedra key generate are not automatically added to your CLI config. They are just files. You can use them by either: (a) running cedra init --private-key <path_to_key> to create a profile with that key, or (b) manually editing your .cedra/config.yaml to reference the private key for a profile.

๐Ÿ”„ Recovering Accounts with Existing Keysโ€‹

If you have an existing private key (from another wallet or a previous backup), you can import it into Cedra CLI to manage that account.

๐Ÿ“ฅ Import via Private Key:

The CLI init command accepts a --private-key argument. If you have the key as a hex string, you can run:

cedra init --private-key <YOUR_PRIVATE_KEY_HEX>

This will set up a new profile using the given key. Once imported, you can use the CLI to view the account (cedra account list) or execute transactions as normal. Key management commands help you handle keys safely outside the blockchain, while account commands manage on-chain entities.

4. Move Project Management (Init, Compile, Test, Publish)โ€‹

One of the Cedra CLI's most powerful features is helping you develop and deploy Move smart contracts. The CLI can create a new Move project, compile it, run Move unit tests, and publish your modules to the blockchain. This section walks through a typical Move development cycle using Cedra CLI.

๐ŸŽฌ Initializing a New Move Projectโ€‹

cedra move init --name <PACKAGE_NAME>

This will create a new folder (named after your package) with a Move.toml file and a sources/ directory.

Next, add your Move source code in the sources/ directory.

๐Ÿ”จ Compiling Move Codeโ€‹

cedra move compile

Make sure you execute this inside the project directory (where Move.toml is located). The CLI will compile your Move modules and any dependencies. If successful, it will produce compiled bytecode in a build/ directory, and list the module IDs (addresses and names) that were compiled. If there are errors, the compiler will display them with file and line numbers so you can fix your code.

Clean Build

If you want to clear the compiled artifacts, you can run cedra move clean. This deletes the build directory. It's not required but helps ensure you're starting fresh.

๐Ÿงช Running Move Unit Testsโ€‹

Move allows you to write unit tests within your modules (functions annotated with #[test]). To execute these tests with the CLI, run:

cedra move test

This will compile the package (in test mode) and run all tests in your code. Output will show which tests passed or failed, along with any debug prints or assertions from the tests. Use this to verify your module's logic off-chain before deploying.

๐Ÿš€ Publishing Move Modules to the Blockchainโ€‹

  1. ๐Ÿ“ค Publish the Package: Run the cedra move publish command (with --named-addresses as needed). The CLI will first simulate the publish transaction (see next section on simulation) and then ask for confirmation to actually submit it. For example:

    cedra move publish --named-addresses my_first_module=default

    On success, you'll get a JSON output with details of the transaction, including a transaction_hash, gas used, the sender, and success: true if it executed.

  2. โœ… Verify on Chain: After publishing, you can use cedra account list --query modules --account <publisher> to see the module in the account's modules list.

5. Transaction Simulation and Executionโ€‹

Before executing any transaction on-chain, it's often useful (or even automatic) to simulate it โ€“ to ensure it will succeed and to estimate gas usage. Cedra CLI provides built-in support for simulating transactions, either on the remote network or locally, and then executing them.

Default Behavior

๐Ÿ” Simulate then Execute: By default, when you run a command like cedra move publish or cedra move run (to execute a Move function), the CLI will first submit the transaction as a simulation to the network's REST API. This means the transaction is run against the current blockchain state without actually committing it, so you can see if it would succeed and how much gas it would use. If the simulation passes (no aborts or errors), the CLI will prompt you to confirm execution. This protects developers from accidentally sending failing transactions. (In technical terms, the CLI "simulation" uses the Cedra fullnode's simulation endpoint under the hood.)

For example, if you run a Move script call:

cedra move run --function-id default::message::set_message --args string:"Hello, Cedra!"

the CLI will simulate this call on the specified network. You might see output indicating a simulation succeeded and a prompt like "Submit transaction (yes/no)?"". After you type "yes", the transaction is submitted to be executed (committed) on chain.

๐Ÿ  Local Simulation Modeโ€‹

Cedra CLI can also simulate transactions entirely locally (without contacting a node). This is useful for rapid feedback or offline analysis. To do this, append the --local flag to your command. For instance:

cedra move run --function-id default::message::set_message --args string:"Test" --local

๐ŸŽฌ Executing (Submitting) Transactionsโ€‹

After simulation, when you confirm, the CLI submits the transaction to the network for execution. If you prefer to skip the interactive confirmation , you can add the --assume-yes flag to any command that prompts. This tells the CLI to proceed without asking, essentially assuming you typed "yes" to all confirmations.

๐ŸŽฏ Example โ€“ Running a Move Functionโ€‹

Suppose you published the message::set_message. To call this function on Testnet via CLI:

cedra move run --function-id <your_address>::message::set_message --args string:"Hello!"

The CLI will:

  1. ๐Ÿ” Simulate the call on the Testnet node (by default).
  2. ๐Ÿ“Š Show you the result (e.g., success and gas cost).
  3. โ“ Prompt for confirmation. If you continue, it will send the transaction for execution.

After execution, you'll get a JSON result similar to other transactions (gas_used, success, etc.). You can then query the account's resources to see the effect (e.g., the MessageHolder resource now stored under that account).

Best Practice

When to Use Simulation: Always! It's good practice to let the CLI simulate transactions first โ€“ this way you avoid wasting gas on mistakes. The simulation results give you a chance to inspect what will happen. For complex or state-changing operations, consider using --local simulation to test different scenarios offline. Use --benchmark and --profile-gas during development to improve your code (for example, to ensure your transaction stays within desired gas limits or to identify which parts of your code are costly).

6. Viewing Resources and Eventsโ€‹

Blockchain applications revolve around resources (Move's persistent data) and events (emitted records of actions). Cedra CLI provides commands to inspect these on-chain, primarily through the account subcommands.

๐Ÿ“‹ Listing Account Resourcesโ€‹

As described, cedra account list --account <addr> will show all Move resources in the account. This is the primary way to view on-chain state for that account. Each resource is output as a JSON object with its fields. For example, a coin resource might look like:

{
"coin": { "value": "1000" },
...
}

Use this command whenever you need to inspect the outcome of transactions. For instance, after calling a set_message function, you could run cedra account list --account default (if default is the affected account) to see the MessageHolder resource now exists and contains the message you stored.

๐Ÿ” Querying Specific Dataโ€‹

The CLI's --query flag can narrow down what you see:

  • --query resources (default) shows all resources.
  • --query balance shows just the coin balance resource with its event handles.
  • --query modules lists the account's modules (bytecode).

If you only care about balances and coin events, use the balance query. If you want the full state dump, use resources. This can be useful for debugging state differences, especially in testing scenarios.

Summary

๐Ÿ“Š Summary: Use Cedra CLI to get a quick snapshot of account state and ensure your transactions did what you expected:

  • After any state-changing transaction (publish, coin transfer, resource modification), run cedra account list on the affected account to see new resource values.
  • Use the queries to focus on balances or confirm modules.
  • For detailed event logs, consult Cedra's explorer or APIs, as CLI outputs only include event counters by default.

7. Useful Utilities (Version Info and Gas Profiling)โ€‹

Finally, Cedra CLI offers some utility commands that can make development easier or provide meta-information about the CLI and your transactions. Two notable ones are checking the CLI version and profiling gas usage.

โ„น๏ธ CLI Version and Infoโ€‹

It's important to know which version of Cedra CLI you are running, especially as Cedra evolves. You can check this in a couple ways:

  • cedra --version โ€“ prints the version number of the CLI (for example, cedra 2.1.0 if using an Cedra build). This is a quick way to verify if you have the latest release.
  • cedra info โ€“ shows detailed build information about the CLI tool. Running this outputs a JSON with fields like build_commit_hash, build_time, and build_pkg_version. This is mostly useful for debugging or when reporting issues (so developers know exactly what build you're using).

For example:

cedra info

might output:

{
"Result": {
"build_branch": "main",
"build_git_rev": "abc1234...",
"build_pkg_version": "1.0.0",
"build_time": "2025-01-15 12:00:00",
"build_os": "macos-aarch64"
}
}

โ›ฝ Gas Profiling Utilityโ€‹

Gas fees are a critical aspect of blockchain transactions. Cedra CLI's gas profiler helps you understand how much gas your transactions consume and where. This is particularly helpful when optimizing smart contracts.

  • ๐Ÿ“ˆ Profiling a Transaction's Gas: To profile gas, add --profile-gas to a transaction execution command. For example:

    cedra move run --function-id default::message::set_message --args string:"Hi" --profile-gas

    When you run this, the CLI will simulate the transaction locally with instrumentation. You'll see output indicating the simulation and where the gas report was saved:

    Simulating transaction locally using the gas profiler...
    Gas report saved to gas-profiling/txn-<XYZ>-<function-name>
    {
    "Result": { "transaction_hash": "...", "gas_used": 441, ... "success": true, ... }
    }

    . The CLI still prints a Result (as if the transaction executed, though it was just a simulation), but crucially it generates a detailed report in a directory called gas-profiling/.

    In your project folder, after running the above, look for a new folder gas-profiling/txn-<something>/. Inside, you will find an index.html along with an assets/ directory. Open index.html in a web browser to view the gas report.