This is a PoC of how to interact with an Hydra head using Tx3.
---
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
// TODO: enumerate each folder and main files within explaining their responsability
- Tx3 toolchain (more info in Tx3 Docs)
- go to
protocol/ - modify
main.tx3file to fit your needs - run
trix bindgento generate the off-chain bindings
The bindings are generated inside the offchain folder as a nodejs package.
- go to
offchain/ - run
npm install && npm run buildto build your client-lib
- go to
app/ - modify
index.tsto fit your app logic - 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);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
}
}
}We use docker & docker compose to run a local Hydra network consisting of an Hydra offline node and a TRP server.
- go to
infra/ - 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
// TODO