# Chain Tactics Local Development & Headless Client

#### Setup Chain Tactics for Local Development

**Installation and Setup**

* Prerequisites:
  * To get started with the Chain Tactics Headless Client, ensure you have the following prerequisites installed and configured:
    * Smart Contract Dependencies:
      * Node.js (v20): Required for package management and script execution.
      * pnpm: Preferred package manager for handling dependencies efficiently.
      * Foundry: A powerful toolkit for developing, testing, and deploying smart contracts. Install via[ https://book.getfoundry.sh/getting-started/installation](https://book.getfoundry.sh/getting-started/installation).
    * Headless Client Dependencies:
      * .NET 9: The runtime required for executing the headless client written in C#.
* Installation Steps & Setup:
  * Unix/Linux Setup:
    * Install npm version 20.
    * Install Foundry:[ https://book.getfoundry.sh/getting-started/installation](https://book.getfoundry.sh/getting-started/installation).
    * Clone: git clone <https://github.com/sovrun/chain-tactics-server>.
    * Run the build\_and\_run\_contract.sh script to deploy the solidity smart contracts to local node.
    * Run the build\_and\_run\_server.sh script to start the server. (Note: On MacOS you may need to enable extra permissions via Apple settings and use the following command sh build\_and\_run\_server.sh )
    * Go to ./tactics-war-sc/packages/contracts/.env and update the following variables:
      * `RPC_URL=http://127.0.0.1:8545  # local chain`
      * `CHAIN_ID=31337                 # local default chain ID`
      * `PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80  # local default anvil account`&#x20;
    * Note: You may change the configurations above to use another chain network (e.g., for testnet, update RPC\_URL to <https://testnet-12-rpc-hyperliquid.sovrun.org/http>).
  * Windows Setup:
    * The same as Unix/Linux setup above, but scripts should be run on Git Bash.

Upon running both scripts, you will now how two terminals with similar output to the following:

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcS12jpIyLpguxIlQc8Kgrpp63qmzf1kAhm7j7vz7qwS7gTh5H5OQmRBURJ74XC-Bmr2_OqjufqXhYZpT-NajI2yN54nsAXIriGgyPQVXM7VEQgb8kY_SlZnkzDs-mMSbCvTUPH?key=weo2vl887S6ZT9ibnwfRY5gJ" alt=""><figcaption><p><strong>build_and_run_contract.sh expected output</strong></p></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXe5xCF3K21N2BCCkfc2GPZy-TFsmVL4sM7qDAHhyAglyiF985JwqJ1R-KNnHtVWy9ZuNRqucghQMQLM_6yrCvecCCCE-hnxktV37avGstfC5V2mY2PANYOtreIbIh1pX81yLuQINw?key=weo2vl887S6ZT9ibnwfRY5gJ" alt=""><figcaption><p>build_and_run_server.sh expected output</p></figcaption></figure>

\
**Game Installation:**

* Download the installer (link provided separately).
* Run and launch the game, then click "Find Match" to play.<br>

**Using the Headless Client**

* Initialization:
  * var client = new CTServerContext("<http://127.0.0.1:8545>");
* Key APIs:
* * GetUnits(): Retrieves units on the board.
  * GetAvailableMoves(): Lists possible moves.
  * ExecuteMove(move): Submits a move to the blockchain.
* Example: List Units:

`using Sovrun.CTServer;`\
`class UnitLister {`\
&#x20;   `static void Main() {`\
&#x20;       `var client = new CTServerContext("http://127.0.0.1:8545");`\
&#x20;       `var units = client.GetUnits();`\
&#x20;       `foreach (var unit in units) {`\
&#x20;           `Console.WriteLine(unit.Name);`\
&#x20;       `}`\
&#x20;   `}`\
`}`

* Note: .NET Standard and Python Bindings are also supported for additional integration options.

**How to Run the Terminal DOTNET Test Implementation Locally**

Testing of the DOTNET server, smart contracts, and local anvil network can be tested via terminal. This is useful for confirming all configurations and code interoperates successfully, before testing on external testnets and mainnets.\ <br>

1. Once you have run the DOTNET server and deployed the smart contracts successfully in separate terminal windows (see Installation), navigate to /tactics-war-server/CTClientExample folder.
2. Run the following command in a third terminal window:

`dotnet run --framework net9.0 http://127.0.0.1:8545 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 0x8d8b6b8414e1e3dcfd4168561b9be6bd3bf6ec4b`

3. In terminal window 4, run the same command, but with the second Anvil default private key:

`dotnet run --framework net9.0 http://127.0.0.1:8545 59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d 0x8d8b6b8414e1e3dcfd4168561b9be6bd3bf6ec4b`

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXej4_Iy9pYTXj28qG4X03-uSaZgfb-h9dgx2xcOfbuy8amRK6G92t7ubd13KU89L-E6cv3f4G7BdRgbPeuL4onMrOhgsTOF2sSJc9G5DsSbWGU4vPiD-BNWRSCAsuY3cPLhhT3Z?key=weo2vl887S6ZT9ibnwfRY5gJ" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sovrun.org/build-with-sovrun/chain-tactics/getting-started-guides/chain-tactics-local-development-and-headless-client.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
