Follow our Medium channel for the entire series:
https://medium.com/@noncegeek/
0x01 Aptos CLI Tool Operations Guide
Source for this article:
1.1 CLI Tool Abstraction Functionality Deconstruction
Regardless of the chain, the CLI tool will include the following functionality in the abstract:
-
Start a local test chain
-
Connecting to a chain node
-
Getting chain information
-
account management
-
Receive test coins (Faucet)
-
transfer (money to a bank account)
-
Deployment Contracts
-
-
contractual interaction
-
Resource View (Only for Move-based Chain)
-
Chain governance (Optional)
1.2 Installing the Aptos CLI
See:
https://aptos.dev/cli-tools/aptos-cli-tool/install-aptos-cli
In general, it is recommended to use the precompiled binary approach, which eliminates the need to compile errors that may be encountered.
1.3 Initializing the Aptos CLI
A local folder named .aptos/ will be created using the configuration config.yaml, which can be used to store the configuration during CLI runs. This is local to your runtime, so you will need to continue to run the CLI from this folder, or reinitialize it in another folder.
If you initialize with default values for everything, the aptos CLI will connect to thelit. test net
Up:
$ . /aptos init Configuring for profile default Enter your rest endpoint [Current: None | No input: https://fullnode.devnet.aptoslabs.com] No rest url given, using https://fullnode.devnet.aptoslabs.com... Enter your faucet endpoint [Current: None | No input: https://faucet.devnet.aptoslabs.com] No faucet url given, using https://faucet.devnet.aptoslabs.com... Enter your private key as a hex literal (0x...) [Current: None | No input: Generate new key (or keep one if present)]] No key given, generating key... Account 50A49D913AA6381C01579E3FC00784B49AFA3A771F06389EBC65F8FF3A4E9A7D doesn't exist, creating it and funding it with 10000 coins Aptos is now set up for account 50A49D913AA6381C01579E3FC00784B49AFA3A771F06389EBC65F8FF3A4E9A7D! Run `aptos help` for more information about commands { "Result": "Success" }
1.4 Starting a Local Test Network and Configuring the CLI
Start the local test chain:
$ . /aptos node run-local-testnet --with-faucet Building genesis with 1 validators. Directory of output: "/Users/liaohua/aptos/.aptos/testnet" Completed generating configuration. Log file: "/Users/liaohua/aptos/.aptos/testnet/validator.log" Test dir: "/Users/liaohua/aptos/.aptos/testnet" Aptos root key path: "/Users/liaohua/aptos/.aptos/testnet/mint.key" Waypoint: 0:81bffa64e06416fe9978f1e91d9f58e222836d303a3984dbd470d2c821a743b2 ChainId: testing REST API endpoint: http://0.0.0.0:8080 Metrics endpoint: http://0.0.0.0:9101/metrics FullNode network: /ip4/0.0.0.0/tcp/6181 Aptos is running, press ctrl-c to exit Faucet is running. Faucet endpoint: 0.0.0.0:8081
Create a new account configuration for the CLI. Note that the window for the above command should not be closed.
$ . /aptos init --profile local --rest-url http://localhost:8080 --faucet-url http://localhost:8081
Configuring for profile local
Using command line argument for rest URL http://localhost:8080/
Using command line argument for faucet URL http://localhost:8081/
Enter your private key as a hex literal (0x...) [Current: None | No input: Generate new key (or keep one) if present)]
No key given, generating key...
Account 4a327db3bce440f47d65b293a9688a7fd59e69a3cc1ddf0b2889a3e4f6d4de62 doesn't exist, creating it and funding it with 10000 coins
Aptos is now set up for account 4a327db3bce440f47d65b293a9688a7fd59e69a3cc1ddf0b2889a3e4f6d4de62! Run `aptos help` for more information about commands
{
"Result": "Success"
}
Local test chain reset:
$ . /aptos node run-local-testnet --with-faucet --force-restart
1.5 Account Management
#. Get the test coins.
$ . /aptos account fund-with-faucet --profile $PROFILE --account $PROFILE
{
"Result": "Added 10000 coins to account 4a327db3bce440f47d65b293a9688a7fd59e69a3cc1ddf0b2889a3e4f6d4de62"
}
# Create resource account
$ . /aptos account create-resource-account --profile $PROFILE --seed 1
Resource Account
ownership is controlled by a resource that can be stored in an account through the Resource Account
We can implement something like the contract account feature in Solidity.
1.6 Resource Viewing
$ . /aptos account list --query resources --account default --profile $PROFILE # or just "account list"
{
"Result": [
{
"0x1::coin::CoinStore": {
"coin": {
"value": "10000"
},
...
]}
1.7 Module View
Different types of queries can be used to view different items under an account. Currently, "Resources" and "Modules" are supported, but more query types will be available soon. For example, to get a module:
$ . /aptos account list --query modules --profile $PROFILE
1.8 Transfer operations
We'll start by creating a new user account, still linked to the local test network:
. /aptos init --profile bob --rest-url http://localhost:8080 --faucet-url http://localhost:8081
Then you can transfer money between different Profiles:
. /aptos account transfer --account bob --amount 100 --profile $PROFILE
1.9 Contract Compilation
in order to hello_blockchain
As an example.
https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/move-examples/hello_blockchain
. /aptos move compile --package-dir [path-to-example]/hello_blockchain --named-addresses hello_blockchain=$PROFILE --profile $PROFILE
The compiled file can be found in theHello, blockchain.
folder to view it.
1.10 Contract deployment
Attention:
The folder needs to be replaced with the
build
folder is deleted or an error will be reported.
. /aptos move publish --package-dir [path-to-example]/move-examples/hello_blockchain --named-addresses hello_blockchain=local --profile $PROFILE
package size 1601 bytes
{
"Result": {
"transaction_hash": "0xe9468512b4aa83be6f0ab1fc49bfc329b2f99fb9db76ec015d90cacdd0649b57", "gas_used": 182
"gas_used": 182,
"gas_unit_price": 1, "gas_unit_price": 1, "gas_unit_price".
"sender": "4a327db3bce440f47d65b293a9688a7fd59e69a3cc1ddf0b2889a3e4f6d4de62",
"sequence_number": 4,
"success": true,
"timestamp_us": 1662198442260668,
"version": 62620, "vm_status": 62620, "vm_status": 62620
"vm_status": "Executed successfully"
}
}
1.11 Contract invocation
. /aptos move run --function-id 4a327db3bce440f47d65b293a9688a7fd59e69a3cc1ddf0b2889a3e4f6d4de62::message::set_message --args string:Hello ! --profile $PROFILE
{
"Result": {
"transaction_hash": "0x9cf6782132a17f4c04047bc4823e26b79811ed94bf524f49c62ca47c25a43028",
"gas_used": 39,
"gas_unit_price": 1,
"sender": "4a327db3bce440f47d65b293a9688a7fd59e69a3cc1ddf0b2889a3e4f6d4de62",
"sequence_number": 5,
"success": true,
"version": 66122, "vm_status": true
"vm_status": "Executed successfully"
}
}
1.13 Generate Keys
aptos key generate --key-type ed25519 --output-file output.key
0x02 REPL Design Recommendations
💡 What is a REPL?
REPL is often referred to as a console, or sometimes as a CLI. REPL is commonly used in our development work:
Bash.
Python REPL: Includes the original
python repl
respond in singingipython
iex: Elixir's REPL
Blockchain REPL:Arguably the standard for blockchains such as
FISCO BCOS
The console andStarcoin CLI
The
A mind-blowingly idealistic REPL should have the following qualities (personal subjective opinion):
2.1 Colorful
Distinguishing different statements by different colors is a good implementation.
2.2 Support for historical queries
There are "weak support" and "strong support". With weak support, it is simple to realize ↑↓ to view the history of commands, and with strong support, you can limit the query range by entering a part, for example, enterprint
After that, press ↑↓ to search for all the inputs.print*
The history of the order.
2.3 Support for Command Completion
Ideally, this could be accomplished bytab
key auto-prompts. However, if command completion is not yet supported, there are--help
Also available.
2.4 Support command help
The convention is to follow the command with--help
to see the command help. On this article, support for theMarkdown
Grammar is a plus.
This article is from a submission and does not represent the position of AptosNews, if reproduced, please cite the source: https://www.aptosnews.com/en/blockchain/210010-html