Skip to content

tx3-lang/hydra-app-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hydra Vending Machine

This is a PoC of how to interact with an Hydra head using Tx3.

Architectural Diagram

---
config:
  layout: dagre
---
flowchart LR
 subgraph Hydra_Network["Hydra Network"]
        HYDRA["Hydra Node"]
        TRP["TRP"]
  end
 subgraph Client_Side["Off-chain"]
        SDK["Tx3 SDK"]
        LIB["Client Lib (codegen)"]
  end
    TRP --> HYDRA
    LIB --> SDK
    SDK -.-> TRP
    APP["APP"] --> LIB
    linkStyle 2 stroke:#FF6D00
Loading

Project Structure

// TODO: enumerate each folder and main files within explaining their responsability

Developing

Pre-requirements

  1. Tx3 toolchain (more info in Tx3 Docs)

Modify your Tx3 protocol

  1. go to protocol/
  2. modify main.tx3 file to fit your needs
  3. run trix bindgen to generate the off-chain bindings

The bindings are generated inside the offchain folder as a nodejs package.

  1. go to offchain/
  2. run npm install && npm run build to build your client-lib

Call your protocol from your app

  1. go to app/
  2. modify index.ts to fit your app logic
  3. use the off-chain client-lib for interacting with the protoccol

Example call from your app logic code:

// import the off-chain lib (codegen)
import { Client } from "my-protocol";

// instantiate a client pointing to your Hydra TRP port
let client = new Client({
  endpoint: "http://localhost:8165",
});

// build a transaction by calling the corresponding function
let tx = client.mintCoinsTx({
  admin: "addr_test1vz5yzy8fttld8yprtzhsz5kuwk46xs9npnfdh3ajaggm5ccyg00d6",
  quantity: 1000,
});

tx.then(console.log);

Running Locally

Configuring the initial UTxO set

Change the contents of the infra/hydra/utxo.json file to define any number of initial UTxOs for the desired addresses. Example:

{
  "0000000000000000000000000000000000000000000000000000000000000000#0": {
    "address": "addr_test1vz5yzy8fttld8yprtzhsz5kuwk46xs9npnfdh3ajaggm5ccyg00d6",
    "value": {
      "lovelace": 100000000
    }
  }
}

Start the infra

We use docker & docker compose to run a local Hydra network consisting of an Hydra offline node and a TRP server.

  1. go to infra/
  2. run docker-compose up

If everything is ok, you should have two containers running and the following ports available:

  • 8165: where the TRP server is listening for request from your off-chain client lib.
  • 4001: the Hydra WS/HTTP port

Stop the infra

// TODO

About

An example vending machine UI using Tx3 and Hydra

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors