|
| 1 | +# Setting Up |
| 2 | + |
| 3 | +This guide walks through the steps to set up and run a Hydra Head using the `kuber-hydra` relay server. We’ll demonstrate the process using two Hydra nodes—**Alice** and **Bob**—on the Cardano testnet. |
| 4 | + |
| 5 | +## **1. Hydra Node Setup** |
| 6 | + |
| 7 | +To set up a Hydra Head on the testnet, follow the official Hydra protocol tutorial: |
| 8 | +👉 [Hydra Head Protocol Documentation](https://hydra.family/head-protocol/docs/tutorial) |
| 9 | + |
| 10 | +In our example setup: |
| 11 | + |
| 12 | +- **Alice's Hydra Node** runs on `172.16.238.10:4001` |
| 13 | +- **Bob's Hydra Node** runs on `172.16.238.20:4002` |
| 14 | + |
| 15 | +## **2. Kuber-Hydra Relay Server** |
| 16 | + |
| 17 | +### **Repository** |
| 18 | + |
| 19 | +- GitHub: [kuber](https://github.com/dquadrant/kuber) |
| 20 | + |
| 21 | +### **Configuration** |
| 22 | + |
| 23 | +You can run `kuber-hydra` either directly or using Docker. |
| 24 | + |
| 25 | +#### **Option 1: Running Natively** |
| 26 | + |
| 27 | +To run `kuber-hydra` natively, you need to set the required environment variables and then run the application using `cabal`. |
| 28 | + |
| 29 | +1. **Set Environment Variables (Required):** |
| 30 | + Before running, you must set the following environment variables: |
| 31 | + ```bash |
| 32 | + export CARDANO_NODE_SOCKET_PATH=/path/to/cardano-node/preview/node.socket |
| 33 | + export NETWORK=2 |
| 34 | + ``` |
| 35 | + - `CARDANO_NODE_SOCKET_PATH`: The path to your Cardano node socket. |
| 36 | + - `NETWORK`: The Cardano network ID (e.g., `2` for Preview testnet). This is a **required** environment variable. |
| 37 | + |
| 38 | +2. **Run `kuber-hydra`:** |
| 39 | + Navigate to the `kuber-hydra` directory and run the application using `cabal`: |
| 40 | + ```bash |
| 41 | + cd kuber-hydra |
| 42 | + cabal run kuber-hydra -- --hydra-url ws://172.16.238.10:4001 --port 8081 |
| 43 | + ``` |
| 44 | + - `--hydra-url`: The WebSocket URL of your Hydra node. This is a **required** command-line argument. |
| 45 | + - `--port`: The port for the Kuber-Hydra relay server. If not specified, it defaults to `8081`. |
| 46 | + |
| 47 | +> The Kuber-Hydra relay API will be accessible at `http://localhost:8081`. |
| 48 | + |
| 49 | +#### **Option 2: Running with Docker (Recommended for quick setup)** |
| 50 | + |
| 51 | +For a quick setup, you can use the provided `docker-compose.yml` to run `kuber-hydra` along with a Cardano node and Hydra node. |
| 52 | + |
| 53 | +1. **Navigate to the `kuber-hydra` directory:** |
| 54 | + ```bash |
| 55 | + cd kuber-hydra |
| 56 | + ``` |
| 57 | +2. **Start the services:** |
| 58 | + ```bash |
| 59 | + docker-compose up -d |
| 60 | + ``` |
| 61 | + This will start `cardano-node`, `hydra-node`, and `kuber-hydra` in detached mode. |
| 62 | + |
| 63 | +3. **Verify services are running:** |
| 64 | + ```bash |
| 65 | + docker-compose ps |
| 66 | + ``` |
| 67 | + Ensure all services are up and healthy. |
| 68 | + |
| 69 | +4. **Access the Kuber-Hydra Relay API:** |
| 70 | + The API will be accessible at `http://localhost:8081`. |
| 71 | + |
| 72 | +## **3. Kuber Client** |
| 73 | + |
| 74 | +Example repository: [kuber-client-example](https://github.com/cardanoapi/kuber-client-example) |
| 75 | + |
| 76 | +### Hydra Service Initialization |
| 77 | + |
| 78 | +Assuming that the hydra node is running and kuber-hdra server is started on localhost:8081, we can pass the host url to this class constructor to create the service: |
| 79 | + |
| 80 | +```ts |
| 81 | +import { KuberHydraService } from "kuber-client/service/kuberHydraService"; |
| 82 | +
|
| 83 | +const hydraService = new KuberHydraService("http://localhost:8081"); |
0 commit comments