github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/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://github.com/tendermint/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 finalize_block Send a set of transactions 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 `finalize_block`, `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://github.com/tendermint/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 87 // Stop upon receiving SIGTERM or CTRL-C. 88 ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) 89 defer cancel() 90 91 srv.SetLogger(logger.With("module", "abci-server")) 92 if err := srv.Start(ctx); err != nil { 93 return err 94 } 95 96 // Run until shutdown. 97 <-ctx.Done() 98 srv.Wait() 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://github.com/tendermint/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 > finalize_block "abc" 173 -> code: OK 174 -> code: OK 175 -> data.hex: 0x0200000000000000 176 177 > commit 178 -> code: OK 179 180 > info 181 -> code: OK 182 -> data: {"size":1} 183 -> data.hex: 0x7B2273697A65223A317D 184 185 > query "abc" 186 -> code: OK 187 -> log: exists 188 -> height: 1 189 -> key: abc 190 -> key.hex: 616263 191 -> value: abc 192 -> value.hex: 616263 193 194 > finalize_block "def=xyz" "ghi=123" 195 -> code: OK 196 -> code: OK 197 -> code: OK 198 -> data.hex: 0x0600000000000000 199 200 > commit 201 -> code: OK 202 203 > query "def" 204 -> code: OK 205 -> log: exists 206 -> height: 2 207 -> key: def 208 -> key.hex: 646566 209 -> value: xyz 210 -> value.hex: 78797A 211 ``` 212 213 Note that if we do `finalize_block "abc" ...` it will store `(abc, abc)`, but if 214 we do `finalize_block "abc=efg" ...` it will store `(abc, efg)`. 215 216 Similarly, you could put the commands in a file and run 217 `abci-cli --verbose batch < myfile`. 218 219 ## Bounties 220 221 Want to write an app in your favorite language?! We'd be happy 222 to add you to our [ecosystem](https://github.com/tendermint/awesome#ecosystem)! 223 See [funding](https://github.com/interchainio/funding) opportunities from the 224 [Interchain Foundation](https://interchain.io/) for implementations in new languages and more. 225 226 The `abci-cli` is designed strictly for testing and debugging. In a real 227 deployment, the role of sending messages is taken by Tendermint, which 228 connects to the app using three separate connections, each with its own 229 pattern of messages. 230 231 For examples of running an ABCI app with 232 Tendermint, see the [getting started guide](./getting-started.md). 233 Next is the ABCI specification.