logo

Introduction to CLI

Introduction to the CLI#

The aelf-command tool is a Command Line Interface (CLI) for interacting with an aelf node. This guide shows you its key features and how to use them.

Features#

  • Configuration Management: Set and get settings like endpoint, account, data directory, and password.
  • Interactive Prompts: Helps new users by asking for missing parameters.
  • Account Management: Create or load accounts with a private key or mnemonic.
  • Wallet Information: Show details like private key, address, public key, and mnemonic.
  • Encryption: Save account info in keyStore format.
  • Blockchain Interaction:
  • User Interface: Uses chalk and ora for better visuals.
  • Chain Status: Get the current status of the chain.
  • Proposal Management: Create proposals on any contract method.
  • Transaction Deserialization: Read results from transactions.
  • Socket.io Server: Start a server for dApps.
  • Installation#

    To install the aelf-command tool globally, use npm:

    1
    npm install aelf-command -g

    Using aelf-command#

    First Step#

    Create a new account or load an existing account using a private key or mnemonic.

    Create a New Wallet

    1
    aelf-command create

    Example output:

    1
    Your wallet info is:
    2
    Mnemonic: great mushroom loan crisp ... door juice embrace
    3
    Private Key: e038eea7e151eb451ba2901f7...b08ba5b76d8f288
    4
    Public Key: 0478903d96aa2c8c0...6a3e7d810cacd136117ea7b13d2c9337e1ec88288111955b76ea
    5
    Address: 2Ue31YTuB5Szy7cnr3SCEGU2gtGi5uMQBYarYUR5oGin1sys6H
    6
    ✔ Save account info into a file? … no / yes
    7
    ✔ Enter a password … **
    8
    ✔ Confirm password … **
    9
    10
    Account info has been saved to "/Users/young/.local/share/aelf/keys/2Ue31YTuB5Szy7cnr...Gi5uMQBYarYUR5oGin1sys6H.json"

    Load Wallet from Private Key

    1
    aelf-command load e038eea7e151eb451ba2901f7...b08ba5b76d8f288

    Example output:

    1
    Your wallet info is:
    2
    Private Key: e038eea7e151eb451ba2901f7...b08ba5b76d8f288
    3
    Public Key: 0478903d96aa2c8c0...6a3e7d810cacd136117ea7b13d2c9337e1ec88288111955b76ea
    4
    Address: 2Ue31YTuB5Szy7cnr3SCEGU2gtGi5uMQBYarYUR5oGin1sys6H
    5
    ✔ Save account info into a file? … no / yes
    6
    ✔ Enter a password … **
    7
    ✔ Confirm password … **
    8
    9
    Account info has been saved to "/Users/young/.local/share/aelf/keys/2Ue31YTuB5Szy7cnr...Gi5uMQBYarYUR5oGin1sys6H.json"

    Show Wallet Info

    1
    aelf-command wallet -a 2Ue31YTuB5Szy7cnr3SCEGU2gtGi5uMQBYarYUR5oGin1sys6H

    Example output:

    1
    Your wallet info is:
    2
    Private Key: e038eea7e151eb451ba2901f7...b08ba5b76d8f288
    3
    Public Key: 0478903d96aa2c8c0...6a3e7d810cacd136117ea7b13d2c9337e1ec88288111955b76ea
    4
    Address: 2Ue31YTuB5Szy7cnr3SCEGU2gtGi5uMQBYarYUR5oGin1sys6H

    Examples#

    Interactive Console

    1
    aelf-command console -a 2Ue31YTuB5Szy7cnr3SCEGU2gtGi5uMQBYarYUR5oGin1sys6H
    2
    ✔ Enter the URI of an AElf node: http://127.0.0.1:8000
    3
    ✔ Enter the password you typed when creating a wallet … **
    4
    ✔ Succeed!
    5
    Welcome to aelf interactive console. Ctrl + C to terminate the program. Double tap Tab to list objects
    6
    7
    ╔═══════════════════════════════════════════════════════════╗
    8
    ║ ║
    9
    ║ NAME | DESCRIPTION ║
    10
    ║ AElf | imported from aelf-sdk ║
    11
    ║ aelf | the instance of an aelf-sdk, connect to ║
    12
    ║ | http://127.0.0.1:8000 ║
    13
    ║ _account | the instance of an AElf wallet, address ║
    14
    ║ | is ║
    15
    ║ | 2Ue31YTuB5Szy7cnr3SCEGU2gtGi5uMQBYarYUR… ║
    16
    ║ | 5oGin1sys6H ║
    17
    ║ ║
    18
    ╚═══════════════════════════════════════════════════════════╝

    Default Parameters

    1
    aelf-command console
    2
    ✔ Enter the URI of an AElf node: http://127.0.0.1:8000
    3
    ✔ Enter a valid wallet address, if you don't have, create one by aelf-command create … 2Ue31YTuB5Szy7cnr3SCEGU2gtGi5uMQBYarYUR5oGin1sys6H
    4
    ✔ Enter the password you typed when creating a wallet … **
    5
    ✔ Succeed!
    6
    Welcome to aelf interactive console. Ctrl + C to terminate the program. Double tap Tab to list objects
    7
    8
    ╔═══════════════════════════════════════════════════════════╗
    9
    ║ ║
    10
    ║ NAME | DESCRIPTION ║
    11
    ║ AElf | imported from aelf-sdk ║
    12
    ║ aelf | the instance of an aelf-sdk, connect to ║
    13
    ║ | http://13.231.179.27:8000 ║
    14
    ║ _account | the instance of an AElf wallet, address ║
    15
    ║ | is ║
    16
    ║ | 2Ue31YTuB5Szy7cnr3SCEGU2gtGi5uMQBYarYUR… ║
    17
    ║ | 5oGin1sys6H ║
    18
    ║ ║
    19
    ╚═══════════════════════════════════════════════════════════╝

    Help#

    To get help, use:

    1
    aelf-command -h

    Output example:

    1
    Usage: aelf-command [command] [options]
    2
    3
    Options:
    4
    -v, --version output the version number
    5
    -e, --endpoint <URI> The URI of an aelf node. Eg: http://127.0.0.1:8000
    6
    -a, --account <account> The address of aelf wallet
    7
    -p, --password <password> The password of encrypted keyStore
    8
    -d, --datadir <directory> The directory that contains the aelf related files. Defaults to {home}/.local/share/aelf
    9
    -h, --help output usage information
    10
    11
    Commands:
    12
    call [contract-address|contract-name] [method] [params] Call a read-only method on a contract.
    13
    send [contract-address|contract-name] [method] [params] Execute a method on a contract.
    14
    get-blk-height Get the current block height of specified chain
    15
    get-chain-status Get the current chain status
    16
    get-blk-info [height|block-hash] [include-txs] Get a block info
    17
    get-tx-result [tx-id] Get a transaction result
    18
    console Open a node REPL
    19
    create [options] [save-to-file] Create a new account
    20
    wallet Show wallet details which include private key, address, public key and mnemonic
    21
    load [private-key|mnemonic] [save-to-file] Load wallet from a private key or mnemonic
    22
    proposal [proposal-contract] [organization] [expired-time] Send a proposal to an origination with a specific contract method
    23
    deploy [category] [code-path] Deprecated! Please use `aelf-command send` , check details in aelf-command `README.md`
    24
    config <flag> [key] [value] Get, set, delete or list aelf-command config
    25
    event [tx-id] Deserialize the result returned by executing a transaction
    26
    dapp-server [options] Start a dAPP SOCKET.IO server

    To get help for a sub-command, such as call, use:

    1
    aelf-command call -h

    Output example:

    1
    Usage: aelf-command call [options] [contract-address|contract-name] [method] [params]
    2
    3
    Call a read-only method on a contract.
    4
    5
    Options:
    6
    -h, --help output usage information
    7
    8
    Examples:
    9
    10
    aelf-command call <contractName|contractAddress> <method> <params>
    11
    aelf-command call <contractName|contractAddress> <method>
    12
    aelf-command call <contractName|contractAddress>
    13
    aelf-command call

    For the interactive console:

    1
    aelf-command console -h

    Output example:

    1
    Usage: aelf-command console [options]
    2
    3
    Open a node REPL
    4
    5
    Options:
    6
    -h, --help output usage information
    7
    8
    Examples:
    9
    10
    aelf-command console

    Edited on: 16 July 2024 05:03:12 GMT+0