Aptos CLI Guide

The aptos utility is a command line interface (CLI) for debugging, development, and node operation. This guide describes how to use the aptos CLI utility.To install the CLI, see the Aptos CLI Installation Guide.

Command Line Reference

Available commands to invoke the Help. Type aptos help or aptos --help to see the available command options.

$ aptos 0.2.1
Aptos Labs <opensource@aptoslabs.com>
CLI tool for interacting with the Aptos blockchain and nodes

USAGE:
    aptos <SUBCOMMAND>

OPTIONS:
    -h, --help       Print help information
    -V, --version    Print version information

SUBCOMMANDS:
    account    CLI tool for interacting with accounts
    config     Tool for configuration of the CLI tool
    genesis    Tool for setting up and building the Genesis transaction
    help       Print this message or the help of the given subcommand(s)
    info       Show information about the build of the CLI
    init       Tool to initialize current directory for the aptos tool
    key        CLI tool for generating, inspecting, and interacting with keys
    move       CLI tool for performing Move tasks
    node       Tool for manipulating nodes
Enter fullscreen mode Exit fullscreen mode

A reference is also available for specific commands. For example, type aptos move --help to get help for a specific command.

$ aptos-move 0.2.1
CLI tool for performing Move tasks

USAGE:
    aptos move <SUBCOMMAND>

OPTIONS:
    -h, --help       Print help information
    -V, --version    Print version information

SUBCOMMANDS:
    compile    Compiles a package and returns the [`ModuleId`]s
    help       Print this message or the help of the given subcommand(s)
    init       Creates a new Move package at the given location
    publish    Publishes the modules in a Move package
    run        Run a Move function
    test       Run Move unit tests against a package path
Enter fullscreen mode Exit fullscreen mode

A subcommand reference is also available. For example, type aptos move compile --help to get help for a specific command.

$ aptos-move-compile 0.2.1
Compiles a package and returns the [`ModuleId`]s

USAGE:
    aptos move compile [OPTIONS]

OPTIONS:
    -h, --help
            Print help information

        --named-addresses <NAMED_ADDRESSES>
            Named addresses for the move binary

            Example: alice=0x1234, bob=0x5678

            Note: This will fail if there are duplicates in the Move.toml file remove those first.

            [default: ]

        --output-dir <OUTPUT_DIR>
            Path to save the compiled move package

            Defaults to `<package_dir>/build`

        --package-dir <PACKAGE_DIR>
            Path to a move package (the folder with a Move.toml file)

    -V, --version
            Print version information
Enter fullscreen mode Exit fullscreen mode

CLI info

To get information about the CLI for debugging, you can run the command aptos info:

$ aptos info
{
  "Result": {
    "build_branch": "main",
    "build_cargo_version": "cargo 1.61.0 (a028ae42f 2022-04-29)",
    "build_commit_hash": "9593a8d515b7c82886064812753b237d82075e35",
    "build_os": "macos-aarch64",
    "build_pkg_version": "0.2.1",
    "build_rust_channel": "1.61.0-aarch64-apple-darwin",
    "build_rust_version": "rustc 1.61.0 (fe5b13d68 2022-05-18)"
  }
}
Enter fullscreen mode Exit fullscreen mode

Examples of settings

Global Configuration Setup

This command can be used to set global configuration parameters for the CLI. The global configuration is located in ~/.aptos/global_config.yaml. At this point the only field that can be configured is --config-type, which allows you to set where the profile configuration will be installed. The default is workspace, which means that the current directory (./.aptos/config.yaml) where the CLI is running will contain the configuration. If global is set, the global directory location (~/.aptos/config.yaml) will be used.

$ aptos config set-global-config --config-type global
{
  "Result": "Success"
}
Enter fullscreen mode Exit fullscreen mode

You can also show the global configuration with show-global-config.

$ aptos config show-global-config
{
  "Result": {
    "config_type": "Global"
  }
}
Enter fullscreen mode Exit fullscreen mode

Setting up shell executions
You can configure shell-completions with generate-shell-completions. Please see the configuration for your particular shell. The following shells are currently supported [bash, zsh, fish, powershell, elvish]. Here is an example for oh my zsh.

$ aptos config generate-shell-completions --shell zsh --output-file ~/.oh-my-zsh/completions/_aptos
Enter fullscreen mode Exit fullscreen mode

Local configuration and account creation

This will create a local .aptos/ folder with config.yaml configuration which you can use to store the configuration between CLI runs. This folder is local to your run, so you will need to continue running the CLI from this folder or re-initialize in another folder.

Step 1: Run Aptos init

This will initialize the configuration with the specified private key.

$ 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"
}
Enter fullscreen mode. Exit fullscreen mode.

Step 2.

To change the configuration you can either do the command aptos init or manually edit the file .aptos/config.yaml which is in your current directory.

Step 3: Create other profiles

You can also create other profiles for different command points and different keys. You can create them by adding the --profile argument, and use them in most other commands to replace command line arguments.

$ aptos init --profile superuser
Configuring for profile superuser
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 18B61497FD290B02BB0751F44381CADA1657C2B3AA6194A00D9BC9A85FAD3B04 doesn't exist, creating it and funding it with 10000 coins
Aptos is now set up for account 18B61497FD290B02BB0751F44381CADA1657C2B3AA6194A00D9BC9A85FAD3B04!  Run `aptos help` for more information about commands
{
  "Result": "Success"
}
Enter fullscreen mode Exit fullscreen mode

Example accounts

Funding an account with faucet

You can top up an account on faucet via the CLI, using either an account or a profile:

$ aptos account fund --account B9BD2CFA58CA29BCE1D7ADD25FCE5C62220604CD0236FE3F90D9DE91ED9FB8CB
{
  "Result": "Added 10000 coins to account B9BD2CFA58CA29BCE1D7ADD25FCE5C62220604CD0236FE3F90D9DE91ED9FB8CB"
}
Enter fullscreen mode Exit fullscreen mode
$ aptos account fund --account default
{
  "Result": "Added 10000 coins to account B9BD2CFA58CA29BCE1D7ADD25FCE5C62220604CD0236FE3F90D9DE91ED9FB8CB"
}
Enter fullscreen mode Exit fullscreen mode

View account balance and transfer information

You can view the balance and information about transfers (depositing and withdrawing funds) by using:

$ aptos account list --query balance --account 0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb
Enter fullscreen mode Exit fullscreen mode

The above command will show the following information on your terminal:

{
  "Result": [
    {
      "coin": {
        "value": "10000"
      },
      "deposit_events": {
        "counter": "1",
        "guid": {
          "id": {
            "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
            "creation_num": "1"
          }
        }
      },
      "withdraw_events": {
        "counter": "0",
        "guid": {
          "id": {
            "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
            "creation_num": "2"
          }
        }
      }
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Invoking Resources in an Account

You can list the resources in an account from the command line. For example, see below how to bring up the resource list in the account you just created above:

$ aptos account list --query resources --account 0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb
Enter fullscreen mode Exit fullscreen mode

The above command will bring up the following information on your terminal about the resource list:

{
  "Result": [
    {
      "coin": {
        "value": "10000"
      },
      "deposit_events": {
        "counter": "1",
        "guid": {
          "id": {
            "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
            "creation_num": "1"
          }
        }
      },
      "withdraw_events": {
        "counter": "0",
        "guid": {
          "id": {
            "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
            "creation_num": "2"
          }
        }
      }
    },
    {
      "register_events": {
        "counter": "1",
        "guid": {
          "id": {
            "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
            "creation_num": "0"
          }
        }
      }
    },
    {
      "counter": "3"
    },
    {
      "authentication_key": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
      "self_address": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
      "sequence_number": "0"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

You can optionally specify a default profile from the configuration, where no account is specified.

$ aptos account list
{
  "Result": [
    {
      "coin": {
        "value": "10000"
      },
      "deposit_events": {
        "counter": "1",
        "guid": {
          "id": {
            "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
            "creation_num": "1"
          }
        }
      },
      "withdraw_events": {
        "counter": "0",
        "guid": {
          "id": {
            "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
            "creation_num": "2"
          }
        }
      }
    },
    {
      "register_events": {
        "counter": "1",
        "guid": {
          "id": {
            "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
            "creation_num": "0"
          }
        }
      }
    },
    {
      "counter": "3"
    },
    {
      "authentication_key": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
      "self_address": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
      "sequence_number": "0"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode.

Alternatively, any place that has an account can use the profile name:

$ aptos account list --query resources --account superuser
{
  "Result": [
    {
      "coin": {
        "value": "10000"
      },
      "deposit_events": {
        "counter": "1",
        "guid": {
          "id": {
            "addr": "0x742854f7dca56ea6309b51e8cebb830b12623f9c9d76c72c3242e4cad353dedc",
            "creation_num": "1"
          }
        }
      },
      "withdraw_events": {
        "counter": "0",
        "guid": {
          "id": {
            "addr": "0x742854f7dca56ea6309b51e8cebb830b12623f9c9d76c72c3242e4cad353dedc",
            "creation_num": "2"
          }
        }
      }
    },
    {
      "register_events": {
        "counter": "1",
        "guid": {
          "id": {
            "addr": "0x742854f7dca56ea6309b51e8cebb830b12623f9c9d76c72c3242e4cad353dedc",
            "creation_num": "0"
          }
        }
      }
    },
    {
      "counter": "3"
    },
    {
      "authentication_key": "0x742854f7dca56ea6309b51e8cebb830b12623f9c9d76c72c3242e4cad353dedc",
      "self_address": "0x742854f7dca56ea6309b51e8cebb830b12623f9c9d76c72c3242e4cad353dedc",
      "sequence_number": "0"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Invoking Modules in an Account

You can call different types of queries to view different items under an account. Currently, "resources" and "modules" are supported, but other types of queries will be available in the future. For example, to retrieve modules:

$ aptos account list --query modules                   
{
  "Result": [
    {
      "bytecode": "0xa11ceb0b050000000b01000a020a12031c2504410405452d0772da0108cc0240068c030a0a9603150cab03650d90040400000101010201030104000506000006080004070700020e0401060100080001000009020300010f0404000410060100031107000002120709010602130a030106050806080105010802020c0a02000103040508020802070801010a0201060c010800010b0301090002070b030109000900074d657373616765056572726f72056576656e74067369676e657206737472696e67124d6573736167654368616e67654576656e740d4d657373616765486f6c64657206537472696e670b6765745f6d6573736167650b7365745f6d6573736167650c66726f6d5f6d6573736167650a746f5f6d657373616765076d657373616765156d6573736167655f6368616e67655f6576656e74730b4576656e7448616e646c65096e6f745f666f756e6404757466380a616464726573735f6f66106e65775f6576656e745f68616e646c650a656d69745f6576656e74b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb0000000000000000000000000000000000000000000000000000000000000001030800000000000000000002020a08020b08020102020c08020d0b030108000001000101030b0a002901030607001102270b002b0110001402010104010105240b0111030c040e0011040c020a02290120030b05120e000b040e00380012012d0105230b022a010c050a051000140c030a050f010b030a04120038010b040b050f0015020100010100",
      "abi": {
        "address": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
        "name": "Message",
        "friends": [],
        "exposed_functions": [
          {
            "name": "get_message",
            "visibility": "public",
            "is_entry": false,
            "generic_type_params": [],
            "params": [
              "address"
            ],
            "return": [
              "0x1::string::String"
            ]
          },
          {
            "name": "set_message",
            "visibility": "public",
            "is_entry": true,
            "generic_type_params": [],
            "params": [
              "signer",
              "vector<u8>"
            ],
            "return": []
          }
        ],
        "structs": [
          {
            "name": "MessageChangeEvent",
            "is_native": false,
            "abilities": [
              "drop",
              "store"
            ],
            "generic_type_params": [],
            "fields": [
              {
                "name": "from_message",
                "type": "0x1::string::String"
              },
              {
                "name": "to_message",
                "type": "0x1::string::String"
              }
            ]
          },
          {
            "name": "MessageHolder",
            "is_native": false,
            "abilities": [
              "key"
            ],
            "generic_type_params": [],
            "fields": [
              {
                "name": "message",
                "type": "0x1::string::String"
              },
              {
                "name": "message_change_events",
                "type": "0x1::event::EventHandle<0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb::Message::MessageChangeEvent>"
              }
            ]
          }
        ]
      }
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Translation

Aptos CLI is also a simple wallet and can transfer coins between accounts.

$ aptos account transfer --account superuser --amount 100
{
  "Result": {
    "gas_used": 73,
    "balance_changes": {
      "742854f7dca56ea6309b51e8cebb830b12623f9c9d76c72c3242e4cad353dedc": {
        "coin": {
          "value": "10100"
        },
        "deposit_events": {
          "counter": "2",
          "guid": {
            "id": {
              "addr": "0x742854f7dca56ea6309b51e8cebb830b12623f9c9d76c72c3242e4cad353dedc",
              "creation_num": "1"
            }
          }
        },
        "withdraw_events": {
          "counter": "0",
          "guid": {
            "id": {
              "addr": "0x742854f7dca56ea6309b51e8cebb830b12623f9c9d76c72c3242e4cad353dedc",
              "creation_num": "2"
            }
          }
        }
      },
      "b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb": {
        "coin": {
          "value": "9827"
        },
        "deposit_events": {
          "counter": "1",
          "guid": {
            "id": {
              "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
              "creation_num": "1"
            }
          }
        },
        "withdraw_events": {
          "counter": "1",
          "guid": {
            "id": {
              "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
              "creation_num": "2"
            }
          }
        }
      }
    },
    "sender": "b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
    "success": true,
    "version": 1139,
    "vm_status": "Executed successfully"
  }
}
Enter fullscreen mode Exit fullscreen mode

Example with keys

Key generation

You can use the command aptos key generate to allow the generation of private keys. You can generate x25519 or ed25519 keys.

$ aptos key generate --key-type ed25519 --output-file output.key
{
  "Result": {
    "PrivateKey Path": "output.key",
    "PublicKey Path": "output.key.pub"
  }
}

Enter fullscreen mode Exit fullscreen mode

Generating Peer Configuration

To allow others to connect to your node, you need to create a peer configuration. The following shows how to use the aptos CLI to create the peer configuration and write it into the peer_config.yaml file.

$ aptos key extract-peer --output-file peer_config.yaml
Enter fullscreen mode Exit fullscreen mode

The above command will show the following result on the terminal:

{
  "Result": {
    "8cfb85603080b13013b57e2e80887c695cfecd7ad8217d1cac22fa6f3b0b5752": {
      "addresses": [],
      "keys": [
        "0x8cfb85603080b13013b57e2e80887c695cfecd7ad8217d1cac22fa6f3b0b5752"
      ],
      "role": "Upstream"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

A file peer_config.yaml will be created in your current working folder, with the contents as shown in the example below:

---
8cfb85603080b13013b57e2e80887c695cfecd7ad8217d1cac22fa6f3b0b5752:
  addresses: []
  keys:
    - "0x8cfb85603080b13013b57e2e80887c695cfecd7ad8217d1cac22fa6f3b0b5752"
  role: Upstream
Enter fullscreen mode Exit fullscreen mode

Note: You must fill in your address line.

MOVE Examples

Build Move

You can use the aptos CLI to build the Move package locally. The example below uses HelloBlockchain in move-examples.

Named addresses can either be an account address or a profile name.

$ aptos move compile --package-dir aptos-move/move-examples/hello_blockchain/ --named-addresses HelloBlockchain=superuser
Enter fullscreen mode Exit fullscreen mode

The above command will print the following output to the terminal:

{
  "Result": [
    "742854F7DCA56EA6309B51E8CEBB830B12623F9C9D76C72C3242E4CAD353DEDC::Message"
  ]
}
Enter fullscreen mode Exit fullscreen mode

Build and unit testing Move

The aptos CLI can also be used to build and run unit tests locally. In this example we will use HelloBlockchain in move-examples.

$ aptos move test --package-dir aptos-move/move-examples/hello_blockchain/ --named-addresses HelloBlockchain=superuser
Enter fullscreen mode Exit fullscreen mode

The above command will show the following result in the terminal:

INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY MoveStdlib
BUILDING Examples
Running Move unit tests
[ PASS    ] 0x742854f7dca56ea6309b51e8cebb830b12623f9c9d76c72c3242e4cad353dedc::MessageTests::sender_can_set_message
[ PASS    ] 0x742854f7dca56ea6309b51e8cebb830b12623f9c9d76c72c3242e4cad353dedc::Message::sender_can_set_message
Test result: OK. Total tests: 2; passed: 2; failed: 0
{
  "Result": "Success"
}
Enter fullscreen mode Exit fullscreen mode

Proof of MOVE

The aptos CLI can be used to run the Move Prover, which is a formal verification tool for the Move language. The example below proves the hello_prover package in move-examples.

aptos move prove --package-dir aptos-move/move-examples/hello_prover/
Enter fullscreen mode Exit fullscreen mode

The above command will print the following result to the terminal:

SUCCESS proving 1 modules from package `hello_prover` in 1.649s
{
  "Result": "Success"
}
Enter fullscreen mode Exit fullscreen mode

Debug and Stacktrace output

In this example we use DebugDemo in a debug-move-example.

First you have to include Move nursery in the Move toml file.

Now you can use Debug::print and Debug::print_stack_trace in your DebugDemo Move file.

You can run the following command:

$ aptos move test --package-dir crates/aptos/debug-move-example
Enter fullscreen mode Exit fullscreen mode

The command will return the following result:

Running Move unit tests
[debug] 0000000000000000000000000000000000000000000000000000000000000001
Call Stack:
    [0] 0000000000000000000000000000000000000000000000000000000000000001::Message::sender_can_set_message

        Code:
            [4] CallGeneric(0)
            [5] MoveLoc(0)
            [6] LdConst(0)
          > [7] Call(1)
            [8] Ret

        Locals:
            [0] -
            [1] 0000000000000000000000000000000000000000000000000000000000000001


Operand Stack:
Enter fullscreen mode Exit fullscreen mode

Publish a Move package with the filename address

In this example we will use HelloBlockchain in move-examples.

Publish the package with your account address set to HelloBlockchain.

Here you need to change 8946741e5c907c43c9e042b3739993f32904723f8e2d1491564d38959b59ac71 to your account address.

$ aptos move publish --package-dir aptos-move/move-examples/hello_blockchain/ --named-addresses HelloBlockchain=8946741e5c907c43c9e042b3739993f32904723f8e2d1491564d38959b59ac71
Enter fullscreen mode Exit fullscreen mode

You can additionally use named profiles for addresses. First holder default.

$ aptos move publish --package-dir aptos-move/move-examples/hello_blockchain/ --named-addresses HelloBlockchain=default
Enter fullscreen mode Exit fullscreen mode

Execute Move

Now that you have published the above function, you can run it.

The arguments must be of type with a colon to separate them. In this example we want the input to be parsed as a string, so we put string:Hello!

$ aptos move run --function-id 0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb::message::set_message --args string:hello!
{
  "Result": {
    "changes": [
      {
        "address": "b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
        "data": {
          "authentication_key": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
          "self_address": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
          "sequence_number": "3"
        },
        "event": "write_resource",
        "resource": "0x1::account::Account"
      },
      {
        "address": "b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
        "data": {
          "coin": {
            "value": "9777"
          },
          "deposit_events": {
            "counter": "1",
            "guid": {
              "id": {
                "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
                "creation_num": "1"
              }
            }
          },
          "withdraw_events": {
            "counter": "1",
            "guid": {
              "id": {
                "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
                "creation_num": "2"
              }
            }
          }
        },
        "event": "write_resource",
        "resource": "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>"
      },
      {
        "address": "b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
        "data": {
          "counter": "4"
        },
        "event": "write_resource",
        "resource": "0x1::guid::Generator"
      },
      {
        "address": "b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
        "data": {
          "message": "hello!",
          "message_change_events": {
            "counter": "0",
            "guid": {
              "id": {
                "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
                "creation_num": "3"
              }
            }
          }
        },
        "event": "write_resource",
        "resource": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb::Message::MessageHolder"
      }
    ],
    "gas_used": 41,
    "success": true,
    "version": 3488,
    "vm_status": "Executed successfully"
  }
} 
Enter fullscreen mode Exit fullscreen mode

Also, profiles can change the addresses in the function identifier.

$ aptos move run --function-id default::message::set_message --args string:hello!
{
  "Result": {
    "changes": [
      {
        "address": "b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
        "data": {
          "authentication_key": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
          "self_address": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
          "sequence_number": "3"
        },
        "event": "write_resource",
        "resource": "0x1::account::Account"
      },
      {
        "address": "b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
        "data": {
          "coin": {
            "value": "9777"
          },
          "deposit_events": {
            "counter": "1",
            "guid": {
              "id": {
                "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
                "creation_num": "1"
              }
            }
          },
          "withdraw_events": {
            "counter": "1",
            "guid": {
              "id": {
                "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
                "creation_num": "2"
              }
            }
          }
        },
        "event": "write_resource",
        "resource": "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>"
      },
      {
        "address": "b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
        "data": {
          "counter": "4"
        },
        "event": "write_resource",
        "resource": "0x1::guid::Generator"
      },
      {
        "address": "b9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
        "data": {
          "message": "hello!",
          "message_change_events": {
            "counter": "0",
            "guid": {
              "id": {
                "addr": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb",
                "creation_num": "3"
              }
            }
          }
        },
        "event": "write_resource",
        "resource": "0xb9bd2cfa58ca29bce1d7add25fce5c62220604cd0236fe3f90d9de91ed9fb8cb::Message::MessageHolder"
      }
    ],
    "gas_used": 41,
    "success": true,
    "version": 3488,
    "vm_status": "Executed successfully"
  }
}
Enter fullscreen mode Exit fullscreen mode

Examples of Noda commands

Starting a local testnet

You can run local testnet from aptos CLI, which will match the version with which it was built. Alternatively, you can run faucet locally with a single node in testnet.

$ aptos node run-local-testnet --with-faucet
Completed generating configuration:
        Log file: "/Users/greg/.aptos/testnet/validator.log"
        Test dir: "/Users/greg/.aptos/testnet"
        Aptos root key path: "/Users/greg/.aptos/testnet/mint.key"
        Waypoint: 0:d302c6b10e0fa68bfec9cdb383f24ef1189d8850d50b832365eea21ae52d8101
        ChainId: TESTING
        REST API endpoint: 0.0.0.0:8080
        FullNode network: /ip4/0.0.0.0/tcp/6181

Aptos is running, press ctrl-c to exit
Enter fullscreen mode Exit fullscreen mode.

This will ensure a stable state, if a node is turned off, it will start from the previous state. If you want to restart the network from genesis, you can add the flag --force-restart.

$ aptos node run-local-testnet --with-faucet --force-restart
Are you sure you want to delete the existing chain? [yes/no] >
yes
Completed generating configuration:
        Log file: "/Users/greg/.aptos/testnet/validator.log"
        Test dir: "/Users/greg/.aptos/testnet"
        Aptos root key path: "/Users/greg/.aptos/testnet/mint.key"
        Waypoint: 0:649efc34c813d0db8db6fa5b1ffc9cc62f726bb5168e7f4b8730bb155d6213ea
        ChainId: TESTING
        REST API endpoint: 0.0.0.0:8080
        FullNode network: /ip4/0.0.0.0/tcp/6181

Aptos is running, press ctrl-c to exit
Enter fullscreen mode Exit fullscreen mode

Genesis Ceremonies

The aptos tool supports the loading of new blockchains through a so-called genesis ceremony. The result of the genesis ceremony is the output of Move commands that prepare the blockchain for online operation. The input consists of:

  • A set of validators and their configuration.
  • The initial set of Move modules, known as the framework
  • A unique ChainId<###code> (u8) that distinguishes this network from other deployments.
  • There is also an account for test networks which manages the AptosCoin mint

Genesis generation.

  • The genesis organizer creates Layout and distributes it.
  • The genesis organizer prepares the bytecode of the Aptos framework and distributes it.
  • Each participant creates their own ValidatorConfiguration and distributes it.
  • Each participant generates a genesis.blob from the contributions received.
  • The genesis organizer executes a genesis.blob to get an initial waypoint and distributes it.
  • Each participant creates their own aptos-node. When launched, the aptos-node checks that the genesis.blob matches the waypoint provided by the genesis organizer.
  • The blockchain will start the consensus once the required stake is accumulated.

Preparing the Aptos-core

The following guide assumes that you have access to the Aptos-core repository or related 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
Enter fullscreen mode Exit fullscreen mode

File Layout.

The Layout file contains:

root_key: the Ed25519 public key to control AptosCoin.

Example:

root_key: "0xca3579457555c80fc7bb39964eb298c414fd60f81a2f8eedb0244ec07a26e575"
users:
  - alice
  - bob
chain_id: 8
Enter fullscreen mode Exit fullscreen mode

Creating Aptos framework

From Aptos-core repository create framework and place it in a folder:

cargo run --package framework
mkdir aptos-framework-release
cp aptos-framework/releases/artifacts/current/build/**/bytecode_modules/* aptos-framework-release
Enter fullscreen mode Exit fullscreen mode

The framework will be stored in the aptos-framework-release directory.

*The ValidatorConfiguration file.

The ValidatorConfiguration file contains:

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
Enter fullscreen mode Exit fullscreen mode

To create it with aptos CLI:

1.Generate validator keys:

cargo run --package aptos -- genesis generate-keys --output-dir bobs
Enter fullscreen mode Exit fullscreen mode

2.Create 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 .
Enter fullscreen mode Exit fullscreen mode

3.The last command will create a file bob.yaml, which should be distributed to others to generate genesis.blob.

Genesis and waypoint generation

The genesis.blob<###code> and waypoint can be generated after receiving the Layout file, each of the individual ValidatorConfiguration files and the framework release. It is important to make sure that the ValidatorConfiguration provided in the previous step matches the distribution to generate the genesis.blob. If there is a mismatch, let all participants know.

To generate genesis.blob and a waypoint:

  • Place the Layout file in a folder such as genesis.
  • Place all the ValidatorConfiguration files in the genesis folder.
  • Make sure that the ValidatorConfiguration files are listed under the users set in Layout.
  • Create a framework folder in the genesiss folder and place the .mv release files of the framework in the framework folder.
  • Use the aptos CLI to generate genesis and waypoint:
cargo run --package aptos -- genesis generate-genesis --local-repository-dir genesis
Enter fullscreen mode Exit fullscreen mode

Launch aptos-node

After generating genesis.blob and waypoint, place them in your validator and fullnode configuration directory and run your validator and fullnode.

Оцените статью
devanswers.ru
Добавить комментарий