code.vegaprotocol.io/vega@v0.79.0/core/examples/README.md (about)

     1  # Examples
     2  
     3  This folder contains examples use-cases which can be built into clients to a local vega system.
     4  
     5  ## Nullchain
     6  
     7  This is a go-package with a high-level of abstraction that gives the ability to manipulate a Vega node running with the `null-blockchain`. The idea is that with this package trading-scenarios can be written from a point of view that doesn't require a lot of technical knowledge of how vega works. For example, the below will connect to vega, create 3 parties, and then move the blockchain forward:
     8  
     9  ```
    10  
    11  func main() {
    12    w := nullchain.NewWallet(config.WalletFolder, config.Passphrase)
    13    conn, _ := nullchain.NewConnection()
    14    parties, err := w.MakeParties(3)
    15  
    16    nullchain.MoveByDuration(config.BlockDuration)
    17  
    18  }
    19  ```
    20  
    21  Prerequistes:
    22  - A Vega node in nullchain mode up and running
    23  - Data-node up and running
    24  - The Faucet up and running
    25  - At least 3 users created in a local vega wallet
    26  - The details in `nullchain/config/config.go` updated to reflect your local environment
    27  
    28  The following bash should get you some way there:
    29  ```
    30  git clone git@github.com:vegaprotocol/vega.git
    31  git clone git@github.com:vegaprotocol/data-node.git
    32  
    33  # cd into vega data-node directories and run
    34  go install ./...
    35  
    36  # initialise vega
    37  vega init -f --home=vegahome
    38  vega nodewallet generate --chain vega --home=vegahome
    39  vega nodewallet generate --chain ethereum --home=vegahome
    40  
    41  # initialise the faucet
    42  vega faucet init -f --home=/vegahome --update-in-place
    43  
    44  # initialise TM just so we can auto-generate a genesis file to fill in
    45  vega tm init --home=vegahome
    46  vega genesis generate --home=vegahome
    47  vega genesis update --tm-home=/tenderminthome --home=/vegahome
    48  
    49  # initialise the data-node
    50  data-node init -f --home=vegahome
    51  
    52  # initialise a vega wallet and make some parties
    53  vega wallet init -f --home=vegahome
    54  vega wallet key generate --wallet=A --home=vegahome
    55  vega wallet key generate --wallet=B --home=vegahome
    56  vega wallet key generate --wallet=C --home=vegahome
    57  ```
    58  
    59  Next you need to fiddle with the vega config file to switch the blockchain on by changing the `BlockChain` section in `vegahome/config/node/config.toml` to look like this:
    60  ```
    61  [Blockchain]
    62    Level = "Info"
    63    LogTimeDebug = true
    64    LogOrderSubmitDebug = true
    65    LogOrderAmendDebug = false
    66    LogOrderCancelDebug = false
    67    ChainProvider = "nullchain"
    68    [Blockchain.Tendermint]
    69      Level = "Info"
    70      LogTimeDebug = true
    71      ClientAddr = "tcp://0.0.0.0:26657"
    72      ClientEndpoint = "/websocket"
    73      ServerPort = 26658
    74      ServerAddr = "localhost"
    75      ABCIRecordDir = ""
    76      ABCIReplayFile = ""
    77    [Blockchain.Null]
    78      Level = "Debug"
    79      BlockDuration = "1s"
    80      TransactionsPerBlock = 3
    81      GenesisFile = "vegahome/config/genesis.json"
    82      IP = "0.0.0.0"
    83      Port = 3101
    84  ```
    85  
    86  Now update the genesis file in `vegahome/config/genesis.json` to include the following assets in the appstate:
    87  
    88  ```
    89  "assets": {
    90        "VOTE": {
    91          "name": "VOTE",
    92          "symbol": "VOTE",
    93          "total_supply": "0",
    94          "decimals": 5,
    95          "min_lp_stake": "1",
    96          "source": {
    97            "builtin_asset": {
    98              "max_faucet_amount_mint": "10000000000"
    99            }
   100          }
   101        },
   102        "XYZ": {
   103          "name": "XYZ",
   104          "symbol": "XYZ",
   105          "total_supply": "0",
   106          "decimals": 5,
   107          "min_lp_stake": "1",
   108          "source": {
   109            "builtin_asset": {
   110              "max_faucet_amount_mint": "10000000000"
   111            }
   112          }
   113        }
   114      },
   115  ```
   116  
   117  Now spin up all the services by running the following each in their own terminal:
   118  
   119  ```
   120  vega node run --home=vegahome
   121  data-node run --home=vegahome
   122  vega faucet run --home=vegahome
   123  
   124  ```
   125  
   126  Once all is running, the example app can be run be doing the following in the `vega` directory
   127  ```
   128  go run ./cmd/examples/nullchain/nullchain
   129  ```