Aptos Command Line Interface (CLI) Tool
The aptos tool is a command line interface (CLI) for debugging, development, and node operation.
This document describes how to install the aptos CLI tool and how to use it.
Installation
Install precompiled binary (easy mode)
- Navigate to the release page for Aptos CLI.
- Download the latest release for your computer.
- Place this at a location for you to run it e.g.
~/bin/aptosin Linux. - On Linux and Mac, make this executable
chmod +x ~/bin/aptos. - Now type
~/bin/aptos helpto read help instructions. - If you want you can add
~/binto your path in your appropriate.bashrcor.zshrcfor future use
Install Cargo (harder mode)
You will need the cargo package manager to install the aptos CLI tool. Follow the below steps.
- Follow the
cargoinstallation instructions on this page and installcargo. Proceed only after you successfully installcargo. - Execute the below step to ensure that your current shell environment knows where
cargois.
Install the aptos CLI
- Install dependencies before compiling:
- For Debian or Ubuntu:
sudo apt install build-essential pkg-config openssl libssl-dev libclang-dev. - For RHEL or Centos:
sudo yum install pkgconfig openssl openssl-devel clang. - For others: please manually install
pkg-configopenssl,libsslandlibclang:pkg-config:- Download and unzip the source code at https://pkgconfig.freedesktop.org/releases/
./configure --prefix=/usr/local/pkg_config/0_29_2 --with-internal-glibsudo make && sudo make install
opensslandlibssl:- Check https://wiki.openssl.org/index.php/Compilation_and_Installation for full instructions.
libclang:- Check https://clang.llvm.org/get_started.html for full instructions.
- For Debian or Ubuntu:
- Install the
aptosCLI tool by running the below command. You can run this command from any directory. TheaptosCLI tool will be installed into yourCARGO_HOME, usually~/.cargo:
- Confirm that the
aptosCLI tool is installed successfully by running the below command. The terminal will display the path to theaptosCLI's location.
Using the aptos CLI
Command Line Help
Command line help is available. Type aptos help or aptos --help to see the available command options.
)
Command specific help is also available. For example, type aptos move --help to get command-specific help.
)
Help for sub-commands is also available. For example, type aptos move compile --help to get command-specific help.
)
Examples
Initialize local configuration and create an account
A local folder named .aptos/ will be created with a configuration config.yaml which can be used
to store configuration between CLI runs. This is local to your run, so you will need to continue running CLI from this
folder, or reinitialize in another folder.
Step 1) Run Aptos init
This will initialize the configuration with the private key given.
) | )
Step 2) Changing the configuration
To change the configuration, you can either run the command aptos init or you can manually edit
the .aptos/config.yaml that is in your current working directory.
Step 3) Creating other profiles
You can also create other profiles for different endpoints and different keys. These can be made
by adding the --profile argument, and can be used in most other commands to replace command line arguments.
) | )
View an account's balance and transfer events
You can view the balance and transfer events (deposits and withdrawals) with:
The above command will generate the following information on your terminal:
{
{
}
}
Listing resources in an account
You can list the resources in an account from the command line. For example, see below for how to list the resources in the account you just created above:
The above command will generate the following resource list information on your terminal:
{
{
}
{
}
{
}
{
}
}
You can additionally list the default profile from configuration with no account specified.
{
{
}
{
}
{
}
{
}
}
Additionally, any place that takes an account can use the name of a profile:
{
{
}
{
}
{
}
{
}
}
Listing modules in an account
You can pass different types of queries to view different items under an account. Currently, 'resources' and 'modules' are supported but more query types are coming. For example, to fetch modules:
$ ./aptos account list --query modules --account superuser
{
"Result": [
{
"bytecode": "0xa11ceb0b050000000b01000a020a12031c2504410405452d0772e00108d202400692030a0a9c03150cb103650d96040400000101010201030104000506000006080001070700030e0401060100080001000009020300020f0404000110060100041107000003120709010603130a030106050806080105010802020c0a02000103040508020802070801010a0201060c010800010b0301090002070b030109000900074d657373616765054153434949064572726f7273054576656e74065369676e6572124d6573736167654368616e67654576656e740d4d657373616765486f6c64657206537472696e670b6765745f6d6573736167650b7365745f6d6573736167650c66726f6d5f6d6573736167650a746f5f6d657373616765076d657373616765156d6573736167655f6368616e67655f6576656e74730b4576656e7448616e646c650d6e6f745f7075626c697368656406737472696e670a616464726573735f6f66106e65775f6576656e745f68616e646c650a656d69745f6576656e747bd2d264eec4088a11c41a7acbcd8ab2d2c887fa4ea1a3ab0d0b4a405ddfb1560000000000000000000000000000000000000000000000000000000000000001030800000000000000000002020a08020b08020102020c08020d0b030108000001000101030b0a002901030607001102270b002b0110001402010200010105240b0111030c040e0011040c020a02290120030b05120e000b040e00380012012d0105230b022a010c050a051000140c030a050f010b030a04120038010b040b050f0015020100010100",
"abi": {
"address": "0x7bd2d264eec4088a11c41a7acbcd8ab2d2c887fa4ea1a3ab0d0b4a405ddfb156",
"name": "Message",
"friends": [],
"exposed_functions": [
{
"name": "get_message",
"visibility": "public",
"generic_type_params": [],
"params": [
"address"
],
"return": [
"0x1::ASCII::String"
]
},
{
"name": "set_message",
"visibility": "script",
"generic_type_params": [],
"params": [
"signer",
"vector"
],
"return": []
}
],
"structs": [
{
"name": "MessageChangeEvent",
"is_native": false,
"abilities": [
"drop",
"store"
],
"generic_type_params": [],
"fields": [
{
"name": "from_message",
"type": "0x1::ASCII::String"
},
{
"name": "to_message",
"type": "0x1::ASCII::String"
}
]
},
{
"name": "MessageHolder",
"is_native": false,
"abilities": [
"key"
],
"generic_type_params": [],
"fields": [
{
"name": "message",
"type": "0x1::ASCII::String"
},
{
"name": "message_change_events",
"type": "0x1::Event::EventHandle<0x7bd2d264eec4088a11c41a7acbcd8ab2d2c887fa4ea1a3ab0d0b4a405ddfb156::Message::MessageChangeEvent>"
}
]
}
]
}
}
]
}
Transferring coins
The Aptos CLI is a simple wallet as well, and can transfer coins between accounts.
{
}
Generating a Peer config
To allow others to connect to your node, you need to generate a peer configuration. Below command shows how you can use
the aptos CLI to generate a peer configuration and write it into a file named peer_config.yaml.
The above command will generate the following output on the terminal:
{
}
The peer_config.yaml file will be created in your current working directory, with the contents as shown in the below example:
Note: In the addresses key, you should fill in your address.
Compiling Move
The aptos CLI can be used to compile a Move package locally.
The below example uses the HelloBlockchain in move-examples.
The above command will generate the below terminal output:
{
}
Compiling & Unit Testing Move
The aptos CLI can also be used to compile and run unit tests locally.
In this example, we'll use the HelloBlockchain in move-examples.
The above command will generate the following terminal output:
[
[
; ;
{
}
Debug and Print Stacktrace
In this example, we will use DebugDemo in debug-move
First, you need to include Move nursery in your Move.toml file toml file
Now, you can use Debug::print and Debug::print_stack_trace in your move file
You can run the following command:
The command will generate the following output:
)
)
)
> [7] )
Publishing a Move Package with a named address
In this example, we'll use the HelloBlockchain in move-examples.
Publish the package with your account address set for HelloBlockchain.
Here, you need to change 8946741e5c907c43c9e042b3739993f32904723f8e2d1491564d38959b59ac71 to your account address.
You can additionally use named profiles for the addresses. The first placeholder is default
Running a Move Function
Now that you've published the function above, you can run it.
Arguments must be given a type with a colon to separate it. In this example, we want the input to be
parsed as a string, so we put string:Hello!.
Additionally, profiles can replace addresses in the function id.
Genesis Ceremonies
The aptos tool supports bootstrapping new blockchains through what is known as a genesis ceremony. The output of the genesis ceremony is the output of move instructions that prepares a blockchain for online operation. The input consists of:
- A set of validators and their configuration
- The initial set of Move modules, known as a framework
- A unique
ChainId(u8) that distinguishes this from other deployments - For test chains, there also exists an account that manages the minting of TestCoin
Generating Genesis
- The genesis organizer constructs a
Layoutand distributes it. - The genesis organizer prepares the Aptos framework's bytecode and distributes it.
- Each participant generates their
ValidatorConfigurationand distributes it. - Each participant generates a
genesis.blobfrom the resulting contributions - The genesis organizer executes the
genesis.blobto derive the initial waypoint and distributes it. - Each participant begins their
aptos-node. Theaptos-nodeverifies upon startup that thegenesis.blobwith the waypoint provided by the genesis organizer . - The blockchain will begin consensus after a quorum of stake is available.
Prepare Aptos-core
The following guide assumes that you have access to the Aptos-core repository or the associated tools. You can download and prepare Aptos-core from GitHub:
git clone https://github.com/aptos-labs/aptos-core.git
cd aptos-core
git checkout --track origin/testnet
./scripts/dev_setup.sh
source ~/.cargo/env
The Layout File
The layout file contains:
root_key: an Ed25519 public key for TestCoin management.users: the set of participantschain_id: theChainIdor a unique integer that distinguishes this deployment from other Aptos networks
An example:
root_key: "0xca3579457555c80fc7bb39964eb298c414fd60f81a2f8eedb0244ec07a26e575"
users:
- alice
- bob
chain_id: 8
Building the Aptos Framework
From your Aptos-core repository, build the framework and package it:
cargo run --package framework
mkdir aptos-framework-release
cp aptos-framework/releases/artifacts/current/build/**/bytecode_modules/* aptos-framework-release
The framework will be stored within the aptos-framework-release directory.
The ValidatorConfiguration File
The ValidatorConfiguration file contains:
account_address: The account that manages this validator. This must be derived from theaccount_keyprovided within teValidatorConfigurationfile.consensus_key: The public key for authenticating consensus messages from the validatoraccount_key: The public key for the account that manages this validator. This is used to derive theaccount_address.network_key: The public key for both validator and fullnode network authentication and encryption.validator_host: The network address where the validator resides. This contains ahostandportfield. Thehostshould either be a DNS name or an IP address. Currently only IPv4 is supported.full_node_host: An optional network address where the fullnode resides. This contains ahostandportfield. Thehostshould either be a DNS name or an IP address. Currently only IPv4 is supported.stake_amount: The number of coins being staked by this node. This is expected to be1, if it is different the configuration will be considered invalid.
An example:
account_address: ccd49f3ea764365ac21e99f029ca63a9b0fbfab1c8d8d5482900e4fa32c5448a
consensus_key: "0xa05b8f41057ac72f9ca99f5e3b1b787930f03ba5e448661f2a1fac98371775ee"
account_key: "0x3d15ab64c8b14c9aab95287fd0eb894aad0b4bd929a5581bcc8225b5688f053b"
network_key: "0x43ce1a4ac031b98bb1ee4a5cd72a4cca0fd72933d64b22cef4f1a61895c2e544"
validator_host:
host: bobs_host
port: 6180
full_node_host:
host: bobs_host
port: 6182
stake_amount: 1
To generate this using the aptos CLI:
- Generate your validator's keys:
cargo run --package aptos -- genesis generate-keys --output-dir bobs
- Generate your
ValidatorConfiguration:
cargo run --package aptos -- \\
genesis set-validator-configuration \\
--keys-dir bobs \\
--username bob \\
--validator-host bobs_host:6180 \\
--full-node-host bobs_host:6180 \\
--local-repository-dir .
- The last command will produce a
bob.yamlfile that should be distributed to other participants forgenesis.blobgeneration.
Generating a Genesis and Waypoint
genesis.blob and the waypoint can be generated after obtaining the Layout file, each of the individual ValidatorConfiguration files, and the framework release. It is important to validate that the ValidatorConfiguration provided in the earlier stage is the same as in the distribution for generating the genesis.blob. If there is a mismatch, inform all participants.
To generate the genesis.blob and waypoint:
- Place the
Layoutfile in a directory, e.g.,genesis. - Place all the
ValidatorConfigurationfiles into thegenesisdirectory. - Ensure that the
ValidatorConfigurationfiles are listed under the set ofuserswithin theLayoutfile. - Make a
frameworkdirectory within thegenesissdirectory and place the framework release.mvfiles into theframeworkdirectory. - Use the
aptosCLI to generate genesis and waypoint:
cargo run --package aptos -- genesis generate-genesis --local-repository-dir genesis
Starting an aptos-node
Upon generating the genesis.blob and waypoint, place them into your validator and fullnode's configuration directory and begin your validator and fullnode.