Skip to content

Commit f7021f8

Browse files
authored
Merge pull request #52 from MeshJS/hydra-docs-update
2 parents 0641378 + 92794a4 commit f7021f8

File tree

5 files changed

+268
-80
lines changed

5 files changed

+268
-80
lines changed

apps/docs/content/docs/hydra/index.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
CardTitle,
1313
} from "@/components/ui/card";
1414

15+
1516
<div className="grid md:grid-cols-2 gap-6 items-stretch">
1617
{linksHydra.map((card) => (
1718
<Link key={card.title} href={card.link} className="no-underline">
@@ -21,4 +22,4 @@ import {
2122
</Card>
2223
</Link>
2324
))}
24-
</div>
25+
</div>
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
---
2+
title: "Hydra Instance"
3+
description: "The HydraInstance is a class interface for interacting with a Hydra head after initialization."
4+
---
5+
6+
import Link from "fumadocs-core/link";
7+
8+
## Overview
9+
10+
The `HydraInstance` is intialized together with `HydraProvider`, for accessing other methods to interact with Hydra head after `HeadIsInitializing` phase.
11+
12+
## Get started:
13+
14+
```tsx
15+
import { HydraInstance, HydraProvider } from "@meshsdk/hydra";
16+
17+
const hydraProvider = new HydraProvider({
18+
httpUrl: "<hydra-API-URL>",
19+
});
20+
21+
const hydraInstance = new HydraInstance({
22+
provider: hydraProvider,
23+
fetcher: "<blockchainProvider>",
24+
submitter: "<blockchainProvider>",
25+
});
26+
```
27+
28+
### Commit Empty
29+
30+
If you don't want to commit any funds and only want to receive on layer 2, you can request an empty commit transaction
31+
to open the head
32+
33+
```tsx
34+
const commit = await hydraInstance.commitEmpty();
35+
const submitTx = await wallet.submitTx(commit);
36+
console.log("submitTx", submitTx);
37+
```
38+
39+
### Commit Funds
40+
41+
Commits funds to the Hydra head by selecting specific UTxOs to make available on layer 2.
42+
**Parameters:**
43+
44+
- `txHash`
45+
- `outputIndex`
46+
47+
**Returns:** The transaction CBOR hex ready to be partially signed
48+
49+
```tsx
50+
await commitFunds(txHash: string, outputIndex: number)
51+
```
52+
53+
```tsx
54+
const txHash =
55+
"00000000000000000000000000000000000000000000000000000000000000000";
56+
const outputIndex = 0;
57+
58+
const commitTx = await hydraInstance.commitFunds(txHash, outputIndex);
59+
const signedTx = await wallet.signTx(commitTx, true);
60+
const commitTxHash = await wallet.submitTx(signedTx);
61+
```
62+
63+
### Commit Blueprint
64+
65+
Commits a Cardano transaction blueprint to the Hydra head.
66+
This is useful for advanced use cases such as commiting `scriptUTxOs`.
67+
68+
**Parameters:**
69+
70+
- `txHash`
71+
- `outputIndex`
72+
- `hydraTransaction`
73+
74+
```tsx
75+
await hydraInstance.commitBlueprint("txHash", outputIndex, {
76+
cborHex: "<unsignedTx>",
77+
description: "commit tx",
78+
type: "Tx ConwayEra",
79+
});
80+
```
81+
82+
```tsx
83+
const commitTx = await hydraInstance.commitBlueprint(txHash, outputIndex, {
84+
cborHex: "<unsignedTx>",
85+
description: "commit tx",
86+
type: "Tx ConwayEra",
87+
});
88+
const signedTx = await wallet.signTx(commitTx, true);
89+
const commitTxHash = await wallet.submitTx(signedTx);
90+
```
91+
92+
### Incremental Commit
93+
94+
Incremental commit methods allow you commit additional UTxOs to an open hydra head after the initial commit:
95+
The time it takes for it top be added after commit depends on the `hydra-node` configuration parameter `--deposit-period`
96+
97+
To read more on incremental commit, see [the Hydra documentation](https://hydra.family/head-protocol/docs/how-to/incremental-commit).
98+
99+
### incrementalCommitFunds
100+
```tsx
101+
await incrementalCommitFunds(txHash: string, outputIndex: number)
102+
```
103+
### incrementalBlueprintCommit
104+
```tsx
105+
await incrementalBlueprintCommit(
106+
txHash,
107+
outputIndex,
108+
{
109+
cborHex: "unsignedTx",
110+
description: "commit tx",
111+
type: "Tx ConwayEra",
112+
}
113+
)
114+
```
115+
116+
## Basic Workflow
117+
118+
### commit Funds
119+
120+
```tsx
121+
import { HydraInstance, HydraProvider } from "@meshsdk/hydra";
122+
import { BlockfrostProvider } from "@meshsdk/core";
123+
124+
const provider = new HydraProvider({
125+
httpUrl: "http://localhost:4001",
126+
});
127+
128+
const hydraInstance = new HydraInstance({
129+
provider: provider,
130+
fetcher: "blockchainProvider",
131+
submitter: "blockchainProvider",
132+
});
133+
134+
await provider.connect();
135+
136+
await provider.init();
137+
138+
const commitTx = await hydraInstance.commitFunds(txHash, outputIndex);
139+
const signedTx = await wallet.signTx(commitTx, true);
140+
await wallet.submitTx(signedTx);
141+
```
142+
143+
### Blueprint Commit
144+
145+
```tsx
146+
const txBuilder = new MeshTxBuilder({
147+
submitter: "blockchainProvider",
148+
fetcher: "blockchainProvider",
149+
verbose: true,
150+
});
151+
152+
const unsignedTx = await txBuilder
153+
.txIn(txHash, outputIndex)
154+
.txOut(address, [{ unit: "lovelace", quantity: amount }])
155+
.setFee("0")
156+
.changeAddress(address)
157+
.selectUtxosFrom(UTxOs)
158+
.complete();
159+
160+
const commitTx = await instance.commitBlueprint(txHash, outputIndex, {
161+
type: "Tx ConwayEra",
162+
cborHex: unsignedTx,
163+
description: "Commit Blueprint",
164+
});
165+
166+
const signedTx = await wallet.signTx(commitTx);
167+
const commitTxHash = await wallet.submitTx(signedTx);
168+
console.log(commitTxHash);
169+
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"title": "Hydra",
3-
"pages": ["tutorial"]
3+
"pages": ["tutorial","instance"]
44
}
55

apps/docs/content/docs/hydra/tutorial.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To initialize Hydra with Mesh, you need to set the `HydraProvider` with the Hydr
1818
import { HydraInstance, HydraProvider } from "@meshsdk/hydra";
1919

2020
const provider = new HydraProvider({
21-
url: "<URL>",
21+
httpUrl: "<URL>",
2222
});
2323

2424
const hydraInstance = new HydraInstance({
@@ -214,7 +214,7 @@ After initialization, both participants need to commit funds to the head. In thi
214214
import { HydraInstance , HydraProvider} from "@meshsdk/hydra";
215215

216216
const provider = new HydraProvider({
217-
url: "<URL>",
217+
httpUrl: "<URL>",
218218
});
219219
const hInstance = new HydraInstance({
220220
provider: provider,

0 commit comments

Comments
 (0)