github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/docs/app-dev/getting-started.md (about)

     1  ---
     2  order: 1
     3  ---
     4  
     5  # Getting Started
     6  
     7  ## First Tendermint App
     8  
     9  As a general purpose blockchain engine, Tendermint is agnostic to the
    10  application you want to run. So, to run a complete blockchain that does
    11  something useful, you must start two programs: one is Tendermint Core,
    12  the other is your application, which can be written in any programming
    13  language. Recall from [the intro to
    14  ABCI](../introduction/what-is-tendermint.md#abci-overview) that Tendermint Core handles all the p2p and consensus stuff, and just forwards transactions to the
    15  application when they need to be validated, or when they're ready to be
    16  committed to a block.
    17  
    18  In this guide, we show you some examples of how to run an application
    19  using Tendermint.
    20  
    21  ### Install
    22  
    23  The first apps we will work with are written in Go. To install them, you
    24  need to [install Go](https://golang.org/doc/install), put
    25  `$GOPATH/bin` in your `$PATH` and enable go modules with these instructions:
    26  
    27  ```bash
    28  echo export GOPATH=\"\$HOME/go\" >> ~/.bash_profile
    29  echo export PATH=\"\$PATH:\$GOPATH/bin\" >> ~/.bash_profile
    30  ```
    31  
    32  Then run
    33  
    34  ```sh
    35  go get github.com/tendermint/tendermint
    36  cd $GOPATH/src/github.com/tendermint/tendermint
    37  make install_abci
    38  ```
    39  
    40  Now you should have the `abci-cli` installed; you'll notice the `kvstore`
    41  command, an example application written
    42  in Go. See below for an application written in JavaScript.
    43  
    44  Now, let's run some apps!
    45  
    46  ## KVStore - A First Example
    47  
    48  The kvstore app is a [Merkle
    49  tree](https://en.wikipedia.org/wiki/Merkle_tree) that just stores all
    50  transactions. If the transaction contains an `=`, e.g. `key=value`, then
    51  the `value` is stored under the `key` in the Merkle tree. Otherwise, the
    52  full transaction bytes are stored as the key and the value.
    53  
    54  Let's start a kvstore application.
    55  
    56  ```sh
    57  abci-cli kvstore
    58  ```
    59  
    60  In another terminal, we can start Tendermint. You should already have the
    61  Tendermint binary installed. If not, follow the steps from
    62  [here](../introduction/install.md). If you have never run Tendermint
    63  before, use:
    64  
    65  ```sh
    66  tendermint init validator
    67  tendermint start
    68  ```
    69  
    70  If you have used Tendermint, you may want to reset the data for a new
    71  blockchain by running `tendermint unsafe-reset-all`. Then you can run
    72  `tendermint start` to start Tendermint, and connect to the app. For more
    73  details, see [the guide on using Tendermint](../tendermint-core/using-tendermint.md).
    74  
    75  You should see Tendermint making blocks! We can get the status of our
    76  Tendermint node as follows:
    77  
    78  ```sh
    79  curl -s localhost:26657/status
    80  ```
    81  
    82  The `-s` just silences `curl`. For nicer output, pipe the result into a
    83  tool like [jq](https://stedolan.github.io/jq/) or `json_pp`.
    84  
    85  Now let's send some transactions to the kvstore.
    86  
    87  ```sh
    88  curl -s 'localhost:26657/broadcast_tx_commit?tx="abcd"'
    89  ```
    90  
    91  Note the single quote (`'`) around the url, which ensures that the
    92  double quotes (`"`) are not escaped by bash. This command sent a
    93  transaction with bytes `abcd`, so `abcd` will be stored as both the key
    94  and the value in the Merkle tree. The response should look something
    95  like:
    96  
    97  ```json
    98  {
    99    "check_tx": { ... },
   100    "deliver_tx": {
   101      "tags": [
   102        {
   103          "key": "YXBwLmNyZWF0b3I=",
   104          "value": "amFl"
   105        },
   106        {
   107          "key": "YXBwLmtleQ==",
   108          "value": "YWJjZA=="
   109        }
   110      ]
   111    },
   112    "hash": "9DF66553F98DE3C26E3C3317A3E4CED54F714E39",
   113    "height": 14
   114  }
   115  ```
   116  
   117  We can confirm that our transaction worked and the value got stored by
   118  querying the app:
   119  
   120  ```sh
   121  curl -s 'localhost:26657/abci_query?data="abcd"'
   122  ```
   123  
   124  The result should look like:
   125  
   126  ```json
   127  {
   128    "response": {
   129      "log": "exists",
   130      "index": "-1",
   131      "key": "YWJjZA==",
   132      "value": "YWJjZA=="
   133    }
   134  }
   135  ```
   136  
   137  Note the `value` in the result (`YWJjZA==`); this is the base64-encoding
   138  of the ASCII of `abcd`. You can verify this in a python 2 shell by
   139  running `"YWJjZA==".decode('base64')` or in python 3 shell by running
   140  `import codecs; codecs.decode(b"YWJjZA==", 'base64').decode('ascii')`.
   141  Stay tuned for a future release that [makes this output more
   142  human-readable](https://github.com/tendermint/tendermint/issues/1794).
   143  
   144  Now let's try setting a different key and value:
   145  
   146  ```sh
   147  curl -s 'localhost:26657/broadcast_tx_commit?tx="name=satoshi"'
   148  ```
   149  
   150  Now if we query for `name`, we should get `satoshi`, or `c2F0b3NoaQ==`
   151  in base64:
   152  
   153  ```sh
   154  curl -s 'localhost:26657/abci_query?data="name"'
   155  ```
   156  
   157  Try some other transactions and queries to make sure everything is
   158  working!
   159  
   160  
   161  ## CounterJS - Example in Another Language
   162  
   163  We also want to run applications in another language - in this case,
   164  we'll run a Javascript version of the `counter`. To run it, you'll need
   165  to [install node](https://nodejs.org/en/download/).
   166  
   167  You'll also need to fetch the relevant repository, from
   168  [here](https://github.com/tendermint/js-abci), then install it:
   169  
   170  ```sh
   171  git clone https://github.com/tendermint/js-abci.git
   172  cd js-abci
   173  npm install abci
   174  ```
   175  
   176  Kill the previous `counter` and `tendermint` processes. Now run the app:
   177  
   178  ```sh
   179  node example/counter.js
   180  ```
   181  
   182  In another window, reset and start `tendermint`:
   183  
   184  ```sh
   185  tendermint reset unsafe-all
   186  tendermint start
   187  ```
   188  
   189  Once again, you should see blocks streaming by - but now, our
   190  application is written in Javascript! Try sending some transactions, and
   191  like before - the results should be the same:
   192  
   193  ```sh
   194  # ok
   195  curl localhost:26657/broadcast_tx_commit?tx=0x00
   196  # invalid nonce
   197  curl localhost:26657/broadcast_tx_commit?tx=0x05
   198  # ok
   199  curl localhost:26657/broadcast_tx_commit?tx=0x01
   200  ```
   201  
   202  Neat, eh?