github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/docs/example/basic-app/README.md (about)

     1  # Example App
     2  
     3  This example contains an example solidity contract [simplestorage](simplestorage.sol) and a [node.js application](app.js) that interacts with the contract using [burrow.js](../../../js/README.md). It also contains a [makefile](makefile) that will set up a single node chain, deploy the contract using `burrow deploy`. The node app configures itself to use the the single node chain my looking for [account.json](account.json) and [deploy.output.json](deploy.output.json) files that are emitted by `burrow deploy` and the makefile.
     4  
     5  The makefile provides some examples of using the `burrow` command line tooling and you are invited to modify it for your purposes (i.e. change from linux target to darwin)
     6  
     7  ## Dependencies
     8  To run the makefile you will need to have installed:
     9  
    10  - GNU Make
    11  - Node.js (the `node` binary)
    12  - npm (the node package manager)
    13  - jq (the JSON tool)
    14  - GO
    15  - Solc (solidity compiler)
    16  
    17  Burrow will be downloaded for you when using the makefile, but you may override `BURROW_BIN` and `BURROW_ARCH` in the makefile to change this behaviour. By default Burrow is downloaded for `Linux_x86_64.
    18  
    19  ## Running the example
    20  
    21  All commands should be run from the same directory as this readme file.
    22  
    23  ### Step one
    24  Start the chain
    25  
    26  ```shell
    27  make start_chain
    28  ```
    29  
    30  This will install burrow, create a new chain as necessary.
    31  
    32  If successful you will see continuous output in your terminal, you can shutdown Burrow by sending the interrupt signal with Ctrl-C, and restart it again with whatever state has accumulated with `make start_chain`. If you would like to destroy the existing chain and start completely fresh (including deleting keys) run `make rechain`. If you would like to keep existing keys and chain config run `make reset_chain`.
    33  
    34  You can redeploy the contract (to a new address) with `make redeploy`. The node app will then use this new contract by reading the address deploy.output.json. Be sure to do this if you wish to modify simplestorage.sol.
    35  
    36  ### Step two
    37  Leave burrow running and in a separate terminal start the app which runs a simple HTTP server with:
    38  
    39  ```shell
    40  make start_app
    41  ```
    42  
    43  This will deploy the contract if necessary, install any node dependencies, and then start an expressjs server, which will run until interrupted.
    44  
    45  ### Step three
    46  In a third terminal you may run the following commands that will call the Solidity smart contract using Javascript and burrow module:
    47  
    48  ```shell
    49  # Inspect current value
    50    $ curl http://127.0.0.1:3000
    51    
    52  # Set the value to 2000
    53    $ curl -d '{"value": 2000}' -H "Content-Type: application/json" -X POST http://127.0.0.1:3000
    54    
    55  # Set the value via a testAndSet operation
    56    $ curl -d '{"value": 30}' -H "Content-Type: application/json" -X POST http://127.0.0.1:3000/2000
    57    
    58  # Attempt the same testAndSet which now fails since the value stored is no longer '2000'
    59    $ curl -d '{"value": 30}' -H "Content-Type: application/json" -X POST http://127.0.0.1:3000/2000
    60    $ curl http://127.0.0.1:3000
    61  ```
    62  
    63  Note: [httpie](https://httpie.org/) is a useful tool that makes POSTing to JSON endpoints more succinct:
    64  
    65  ```shell
    66  # Inspect current value
    67    $ http 127.0.0.1:3000
    68    
    69  # Set the value to 2000
    70    $ http 127.0.0.1:3000 value=2000
    71    
    72  # Set the value via a testAndSet operation
    73    $ http 127.0.0.1:3000/2000 value=30
    74    
    75  # Attempt the same testAndSet which now fails since the value stored is no longer '2000'
    76    $ http 127.0.0.1:3000/2000 value=30
    77    $ http 127.0.0.1:3000
    78  ```
    79  
    80  ## Additional endpoints
    81  
    82  ### Sending value and creating accounts
    83  
    84  An endpoint is provided at `/send` for sending value from the default input account (defined in account.json after making the chain) that can be used with:
    85  
    86  ```shell
    87  # Send 1000 units of native token to D1293FE65A071A9DB539D64858F0A3D4BCAA2EBA
    88    http :3000/send/D1293FE65A071A9DB539D64858F0A3D4BCAA2EBA amount=1000
    89  ```