github.com/KYVENetwork/cometbft/v38@v38.0.3/docs/app-dev/abci-cli.md (about)

     1  ---
     2  order: 3
     3  ---
     4  
     5  # Using ABCI-CLI
     6  
     7  To facilitate testing and debugging of ABCI servers and simple apps, we
     8  built a CLI, the `abci-cli`, for sending ABCI messages from the command
     9  line.
    10  
    11  ## Install
    12  
    13  Make sure you [have Go installed](https://golang.org/doc/install).
    14  
    15  Next, install the `abci-cli` tool and example applications:
    16  
    17  ```sh
    18  git clone https://github.com/cometbft/cometbft.git
    19  cd cometbft
    20  make install_abci
    21  ```
    22  
    23  Now run `abci-cli` to see the list of commands:
    24  
    25  ```sh
    26  Usage:
    27    abci-cli [command]
    28  
    29  Available Commands:
    30    batch            run a batch of abci commands against an application
    31    check_tx         validate a transaction
    32    commit           commit the application state and return the Merkle root hash
    33    completion       Generate the autocompletion script for the specified shell
    34    console          start an interactive ABCI console for multiple commands
    35    echo             have the application echo a message
    36    finalize_block   deliver a block of transactions to the application
    37    help             Help about any command
    38    info             get some info about the application
    39    kvstore          ABCI demo example
    40    prepare_proposal prepare proposal
    41    process_proposal process proposal
    42    query            query the application state
    43    test             run integration tests
    44    version          print ABCI console version
    45  
    46  Flags:
    47        --abci string        either socket or grpc (default "socket")
    48        --address string     address of application socket (default "tcp://0.0.0.0:26658")
    49    -h, --help               help for abci-cli
    50        --log_level string   set the logger level (default "debug")
    51    -v, --verbose            print the command and results as if it were a console session
    52  
    53  Use "abci-cli [command] --help" for more information about a command.
    54  ```
    55  
    56  ## KVStore - First Example
    57  
    58  The `abci-cli` tool lets us send ABCI messages to our application, to
    59  help build and debug them.
    60  
    61  The most important messages are `deliver_tx`, `check_tx`, and `commit`,
    62  but there are others for convenience, configuration, and information
    63  purposes.
    64  
    65  We'll start a kvstore application, which was installed at the same time as
    66  `abci-cli` above. The kvstore just stores transactions in a Merkle tree. Its
    67  code can be found
    68  [here](https://github.com/KYVENetwork/cometbft/v38/blob/v0.38.x/abci/example/kvstore/kvstore.go).
    69  
    70  Start the application by running:
    71  
    72  ```sh
    73  abci-cli kvstore
    74  ```
    75  
    76  And in another terminal, run
    77  
    78  ```sh
    79  abci-cli echo hello
    80  abci-cli info
    81  ```
    82  
    83  You'll see something like:
    84  
    85  ```sh
    86  -> data: hello
    87  -> data.hex: 68656C6C6F
    88  ```
    89  
    90  and:
    91  
    92  ```sh
    93  -> data: {"size":0}
    94  -> data.hex: 7B2273697A65223A307D
    95  ```
    96  
    97  An ABCI application must provide two things:
    98  
    99  - a socket server
   100  - a handler for ABCI messages
   101  
   102  When we run the `abci-cli` tool we open a new connection to the
   103  application's socket server, send the given ABCI message, and wait for a
   104  response.
   105  
   106  The server may be generic for a particular language, and we provide a
   107  [reference implementation in
   108  Golang](https://github.com/KYVENetwork/cometbft/v38/tree/v0.38.x/abci/server). See the
   109  [list of other ABCI implementations](https://github.com/tendermint/awesome#ecosystem) for servers in
   110  other languages.
   111  
   112  The handler is specific to the application, and may be arbitrary, so
   113  long as it is deterministic and conforms to the ABCI interface
   114  specification.
   115  
   116  So when we run `abci-cli info`, we open a new connection to the ABCI
   117  server, which calls the `Info()` method on the application, which tells
   118  us the number of transactions in our Merkle tree.
   119  
   120  Now, since every command opens a new connection, we provide the
   121  `abci-cli console` and `abci-cli batch` commands, to allow multiple ABCI
   122  messages to be sent over a single connection.
   123  
   124  Running `abci-cli console` should drop you in an interactive console for
   125  speaking ABCI messages to your application.
   126  
   127  Try running these commands:
   128  
   129  ```sh
   130  > echo hello
   131  -> code: OK
   132  -> data: hello
   133  -> data.hex: 0x68656C6C6F
   134  
   135  > info
   136  -> code: OK
   137  -> data: {"size":0}
   138  -> data.hex: 0x7B2273697A65223A307D
   139  
   140  > prepare_proposal "abc=123"
   141  -> code: OK
   142  -> log: Succeeded. Tx: abc=123
   143  
   144  > process_proposal "abc==456"
   145  -> code: OK
   146  -> status: REJECT
   147  
   148  > process_proposal "abc=123"
   149  -> code: OK
   150  -> status: ACCEPT
   151  
   152  > finalize_block "abc=123"
   153  -> code: OK
   154  -> code: OK
   155  -> data.hex: 0x0200000000000000
   156  
   157  > commit
   158  -> code: OK
   159  
   160  > info
   161  -> code: OK
   162  -> data: {"size":1}
   163  -> data.hex: 0x7B2273697A65223A317D
   164  
   165  > query "abc"
   166  -> code: OK
   167  -> log: exists
   168  -> height: 0
   169  -> key: abc
   170  -> key.hex: 616263
   171  -> value: 123
   172  -> value.hex: 313233
   173  
   174  > finalize_block "def=xyz" "ghi=123"
   175  -> code: OK
   176  -> code: OK
   177  -> code: OK
   178  -> data.hex: 0x0600000000000000
   179  
   180  > commit
   181  -> code: OK
   182  
   183  > query "def"
   184  -> code: OK
   185  -> log: exists
   186  -> height: 0
   187  -> key: def
   188  -> key.hex: 646566
   189  -> value: xyz
   190  -> value.hex: 78797A
   191  ```
   192  
   193  Note that if we do `finalize_block "abc" ...` it will store `(abc, abc)`, but if
   194  we do `finalize_block "abc=efg" ...` it will store `(abc, efg)`.
   195  
   196  You could put the commands in a file and run
   197  `abci-cli --verbose batch < myfile`.
   198  
   199  
   200  Note that the `abci-cli` is designed strictly for testing and debugging. In a real
   201  deployment, the role of sending messages is taken by CometBFT, which
   202  connects to the app using four separate connections, each with its own
   203  pattern of messages.
   204  
   205  For examples of running an ABCI app with CometBFT, see the
   206  [getting started guide](./getting-started.md).
   207  
   208  ## Bounties
   209  
   210  Want to write an app in your favorite language?! We'd be happy
   211  to add you to our [ecosystem](https://github.com/tendermint/awesome#ecosystem)!
   212  See [funding](https://github.com/interchainio/funding) opportunities from the
   213  [Interchain Foundation](https://interchain.io) for implementations in new languages and more.