bitbucket.org/number571/tendermint@v0.8.14/docs/app-dev/abci-cli.md (about)

     1  ---
     2  order: 2
     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://bitbucket.org/number571/tendermint.git
    19  cd tendermint
    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 tx
    32    commit      Commit the application state and return the Merkle root hash
    33    console     Start an interactive abci console for multiple commands
    34    deliver_tx  Deliver a new tx to the application
    35    kvstore     ABCI demo example
    36    echo        Have the application echo a message
    37    help        Help about any command
    38    info        Get some info about the application
    39    query       Query the application state
    40    set_option  Set an options on the application
    41  
    42  Flags:
    43        --abci string      socket or grpc (default "socket")
    44        --address string   address of application socket (default "tcp://127.0.0.1:26658")
    45    -h, --help             help for abci-cli
    46    -v, --verbose          print the command and results as if it were a console session
    47  
    48  Use "abci-cli [command] --help" for more information about a command.
    49  ```
    50  
    51  ## KVStore - First Example
    52  
    53  The `abci-cli` tool lets us send ABCI messages to our application, to
    54  help build and debug them.
    55  
    56  The most important messages are `deliver_tx`, `check_tx`, and `commit`,
    57  but there are others for convenience, configuration, and information
    58  purposes.
    59  
    60  We'll start a kvstore application, which was installed at the same time
    61  as `abci-cli` above. The kvstore just stores transactions in a merkle
    62  tree.
    63  
    64  Its code can be found
    65  [here](https://bitbucket.org/number571/tendermint/blob/master/abci/cmd/abci-cli/abci-cli.go)
    66  and looks like:
    67  
    68  ```go
    69  func cmdKVStore(cmd *cobra.Command, args []string) error {
    70      logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
    71  
    72      // Create the application - in memory or persisted to disk
    73      var app types.Application
    74      if flagPersist == "" {
    75          app = kvstore.NewKVStoreApplication()
    76      } else {
    77          app = kvstore.NewPersistentKVStoreApplication(flagPersist)
    78          app.(*kvstore.PersistentKVStoreApplication).SetLogger(logger.With("module", "kvstore"))
    79      }
    80  
    81      // Start the listener
    82      srv, err := server.NewServer(flagAddrD, flagAbci, app)
    83      if err != nil {
    84          return err
    85      }
    86      srv.SetLogger(logger.With("module", "abci-server"))
    87      if err := srv.Start(); err != nil {
    88          return err
    89      }
    90  
    91      // Stop upon receiving SIGTERM or CTRL-C.
    92      tmos.TrapSignal(logger, func() {
    93          // Cleanup
    94          srv.Stop()
    95      })
    96  
    97      // Run forever.
    98      select {}
    99  }
   100  ```
   101  
   102  Start by running:
   103  
   104  ```sh
   105  abci-cli kvstore
   106  ```
   107  
   108  And in another terminal, run
   109  
   110  ```sh
   111  abci-cli echo hello
   112  abci-cli info
   113  ```
   114  
   115  You'll see something like:
   116  
   117  ```sh
   118  -> data: hello
   119  -> data.hex: 68656C6C6F
   120  ```
   121  
   122  and:
   123  
   124  ```sh
   125  -> data: {"size":0}
   126  -> data.hex: 7B2273697A65223A307D
   127  ```
   128  
   129  An ABCI application must provide two things:
   130  
   131  - a socket server
   132  - a handler for ABCI messages
   133  
   134  When we run the `abci-cli` tool we open a new connection to the
   135  application's socket server, send the given ABCI message, and wait for a
   136  response.
   137  
   138  The server may be generic for a particular language, and we provide a
   139  [reference implementation in
   140  Golang](https://bitbucket.org/number571/tendermint/tree/master/abci/server). See the
   141  [list of other ABCI implementations](https://github.com/tendermint/awesome#ecosystem) for servers in
   142  other languages.
   143  
   144  The handler is specific to the application, and may be arbitrary, so
   145  long as it is deterministic and conforms to the ABCI interface
   146  specification.
   147  
   148  So when we run `abci-cli info`, we open a new connection to the ABCI
   149  server, which calls the `Info()` method on the application, which tells
   150  us the number of transactions in our Merkle tree.
   151  
   152  Now, since every command opens a new connection, we provide the
   153  `abci-cli console` and `abci-cli batch` commands, to allow multiple ABCI
   154  messages to be sent over a single connection.
   155  
   156  Running `abci-cli console` should drop you in an interactive console for
   157  speaking ABCI messages to your application.
   158  
   159  Try running these commands:
   160  
   161  ```sh
   162  > echo hello
   163  -> code: OK
   164  -> data: hello
   165  -> data.hex: 0x68656C6C6F
   166  
   167  > info
   168  -> code: OK
   169  -> data: {"size":0}
   170  -> data.hex: 0x7B2273697A65223A307D
   171  
   172  > commit
   173  -> code: OK
   174  -> data.hex: 0x0000000000000000
   175  
   176  > deliver_tx "abc"
   177  -> code: OK
   178  
   179  > info
   180  -> code: OK
   181  -> data: {"size":1}
   182  -> data.hex: 0x7B2273697A65223A317D
   183  
   184  > commit
   185  -> code: OK
   186  -> data.hex: 0x0200000000000000
   187  
   188  > query "abc"
   189  -> code: OK
   190  -> log: exists
   191  -> height: 2
   192  -> value: abc
   193  -> value.hex: 616263
   194  
   195  > deliver_tx "def=xyz"
   196  -> code: OK
   197  
   198  > commit
   199  -> code: OK
   200  -> data.hex: 0x0400000000000000
   201  
   202  > query "def"
   203  -> code: OK
   204  -> log: exists
   205  -> height: 3
   206  -> value: xyz
   207  -> value.hex: 78797A
   208  ```
   209  
   210  Note that if we do `deliver_tx "abc"` it will store `(abc, abc)`, but if
   211  we do `deliver_tx "abc=efg"` it will store `(abc, efg)`.
   212  
   213  Similarly, you could put the commands in a file and run
   214  `abci-cli --verbose batch < myfile`.
   215  
   216  ## Bounties
   217  
   218  Want to write an app in your favorite language?! We'd be happy
   219  to add you to our [ecosystem](https://github.com/tendermint/awesome#ecosystem)!
   220  See [funding](https://github.com/interchainio/funding) opportunities from the
   221  [Interchain Foundation](https://interchain.io/) for implementations in new languages and more.
   222  
   223  The `abci-cli` is designed strictly for testing and debugging. In a real
   224  deployment, the role of sending messages is taken by Tendermint, which
   225  connects to the app using three separate connections, each with its own
   226  pattern of messages.
   227  
   228  For examples of running an ABCI app with
   229  Tendermint, see the [getting started guide](./getting-started.md).
   230  Next is the ABCI specification.