Skip to content

Commit 5e8791c

Browse files
committed
Fix: update docs
1 parent 7ee7780 commit 5e8791c

File tree

2 files changed

+95
-77
lines changed

2 files changed

+95
-77
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,

apps/docs/content/docs/providers/hydra.mdx

Lines changed: 94 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: "Hydra Provider (beta)"
33
desceription: "Layer 2 scaling solution for Cardano that increases transaction throughput and ensures cost efficiency while maintaining security."
44
---
5+
56
import Link from "fumadocs-core/link";
67

78
The <Link href="https://hydra.family/head-protocol/">Hydra Head protocol</Link> is a layer 2 scaling solution for Cardano rooted in peer-reviewed research that increases transaction throughput and ensures cost efficiency while maintaining rigorous security.
@@ -13,66 +14,80 @@ import { HydraProvider } from "@meshsdk/hydra";
1314

1415
// Hydra Head URL and PORT: e.g. http://123.45.67.890:4001
1516

16-
const provider = new HydraProvider('<URL>');
17-
await provider.connect();
17+
const provider = new HydraProvider("<httpUrl>");
1818
```
1919

20+
## connect
2021

21-
## Connect Hydra Head
22-
23-
Connects to the Hydra Head. This command is a no-op when a Head is already open.
22+
Establishes a connection to a Hydra Head. This is typically managed through the HydraProvider..
2423

2524
```tsx
2625
await provider.connect();
2726
```
2827

28+
## disconnect
29+
30+
Closes the active connection to a Hydra Head. This is typically managed through the HydraProvider.
2931

30-
## Initializes a new Hydra Head
32+
Parameter (Optional)
3133

32-
Initializes a new Head. This command is a no-op when a Head is already open and the server will output an `CommandFailed` message should this happen.
34+
- timeout: Specifies the timeout duration in milliseconds. The default timeout is 5 minutes (300,000 ms).
3335

3436
```tsx
35-
await provider.init();
37+
// Disconnect with default timeout (5 minutes)
38+
await disconnect(timeout);
39+
40+
// Disconnect with custom timeout (e.g., 10 minutes)
41+
await disconnect(10 * 60 * 1000);
3642
```
3743

44+
## Hydra commands APIs
3845

39-
## Commit to Hydra Head
46+
### Initialize
4047

41-
Commit a particular UTxO to the head. This will make the UTxO available on the layer 2.
48+
Initializes a new Head. This command is a no-op when a Head is already open and the server will
49+
output an `CommandFailed` message should this happen.
4250

4351
```tsx
44-
// Params: CommitUtxo, KeyToSign
45-
await instance.commit("", undefined);
52+
await provider.init();
4653
```
4754

55+
### Abort
4856

49-
## Aborts a head
50-
51-
Aborts a head before it is opened. This can only be done before all participants have committed. Once opened, the head can't be aborted anymore but it can be closed using: `Close`.
57+
Aborts a head before it is opened. This can only be done before all participants have committed.
58+
Once opened, the head can't be aborted anymore but it can be closed using: `Close`.
5259

5360
```tsx
5461
await provider.abort();
5562
```
5663

64+
### Commit
5765

58-
## New Transaction
66+
Commit a particular UTxO to the head. This will make the UTxO available on the layer 2.
67+
This is used together with the [`HydraInstance`](../hydra/instance) (see the Hydra Instance page for details).
5968

60-
Submit a transaction through the head. Note that the transaction is only broadcast if well-formed and valid.
69+
```tsx
70+
await instance.commitFunds(txHash, outputIndex);
71+
```
6172

62-
You can also the `await provider.submitTx(signedTx)` method to submit a signed transaction.
73+
### New Transaction
6374

75+
Submit a transaction through the head. Note that the transaction is only broadcast if well-formed and valid.
6476
The `newTx` method accepts the following arguments:
6577

78+
**parameters**
79+
80+
- cborHex: This is the transaction in hex format usually the unsigned transaction.
81+
- type: Any transaction is tried to decode as a 'ConwayEra' transaction, which mostly is backward compatible to previous eras.
82+
- description(optional): transaction description
83+
6684
```tsx
67-
async newTx(
68-
cborHex: string,
69-
type:
70-
| "Tx ConwayEra"
71-
| "Unwitnessed Tx ConwayEra"
72-
| "Witnessed Tx ConwayEra",
73-
description = "",
74-
txId?: string
75-
)
85+
async newTx({
86+
cborHex: "<unsignedTx>",
87+
description: "commit tx",
88+
type: "Tx ConwayEra",
89+
})
90+
7691
```
7792

7893
Here is an example of how to create a transaction using the Hydra provider, Mesh wallet and Mesh transaction builder:
@@ -105,10 +120,9 @@ async function makeTx() {
105120
});
106121

107122
const unsignedTx = await txBuilder
108-
.txOut(
109-
"addr_test1vpd5axpq4qsh8sxvzny49cp22gc5tqx0djf6wmjv5cx7q5qyrzuw8",
110-
[{ unit: "lovelace", quantity: "3000000" }],
111-
)
123+
.txOut("addr_test1vpd5axpq4qsh8sxvzny49cp22gc5tqx0djf6wmjv5cx7q5qyrzuw8", [
124+
{ unit: "lovelace", quantity: "3000000" },
125+
])
112126
.changeAddress(changeAddress)
113127
.selectUtxosFrom(utxos)
114128
.complete();
@@ -119,80 +133,66 @@ async function makeTx() {
119133
}
120134
```
121135

122-
123-
## Decommit
136+
### Decommit
124137

125138
Request to decommit a UTxO from a Head by providing a decommit tx. Upon reaching consensus, this will eventually result in corresponding transaction outputs becoming available on the layer 1.
126139

127140
The decommit method accepts the following arguments:
128141

129142
```tsx
130-
async decommit(
131-
cborHex: string,
132-
type:
133-
| "Tx ConwayEra"
134-
| "Unwitnessed Tx ConwayEra"
135-
| "Witnessed Tx ConwayEra",
136-
description = "",
137-
)
143+
async decommit({
144+
cborHex: "<unsignedTx>",
145+
description: "commit tx",
146+
type: "Tx ConwayEra"
147+
})
138148
```
139149

140-
141-
## Close Hydra Head
150+
### Close
142151

143152
Terminate a head with the latest known snapshot. This effectively moves the head from the Open state to the Close state where the contestation phase begin. As a result of closing a head, no more transactions can be submitted via NewTx.
144153

145154
```tsx
146155
await provider.close();
147156
```
148157

158+
### Contest
149159

150-
## Contest
151-
152-
Challenge the latest snapshot announced as a result of a head closure from another participant. Note that this necessarily contest with the latest snapshot known of your local Hydra node. Participants can only contest once.
160+
Challenge the latest snapshot announced as a result of a head closure from another participant.
161+
Note that this necessarily contest with the latest snapshot known of your local Hydra node. Participants can only contest once.
153162

154163
```tsx
155164
await provider.contest();
156165
```
157166

167+
### Fanout
158168

159-
## Fanout
160-
161-
Finalize a head after the contestation period passed. This will distribute the final (as closed and maybe contested) head state back on the layer 1.
169+
Finalize a head UTxOs to L1 after the contestation period passed.
162170

163171
```tsx
164172
await provider.fanout();
165173
```
166174

167-
168-
## Listens for new messages from Hydra node
169-
170-
Listens for new messages from Hydra node. The callback function will be called with the message as the only argument. Check <Link href="https://hydra.family/head-protocol/api-reference">all events emitted</Link> by the Hydra node.
171-
172-
```tsx
173-
provider.onMessage((message) => {
174-
console.log("HydraProvider received message", message);
175-
// do something with the message
176-
});
177-
```
178-
179-
The callback function is typed, so you can access the message properties directly.
180-
181175
```tsx
182176
provider.onMessage((message) => {
183-
if (message.tag === "Greetings") {
184-
console.log("message.snapshotUtxo", message.snapshotUtxo);
177+
if (
178+
message.headStatus === "FanoutPossible" ||
179+
message.tag === "HeadIsFinalized"
180+
) {
181+
provider.fanout();
185182
}
186183
});
187184
```
188185

186+
## Hydra Query APIs
189187

190-
## Fetch Address UTxOs
188+
### Fetch Address UTxOs
191189

192190
Fetch UTxOs controlled by an address.
193191

194192
```tsx
195-
await provider.fetchAddressUTxOs('addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9')
193+
await provider.fetchAddressUTxOs(
194+
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9"
195+
);
196196
```
197197

198198
Optionally, you can filter UTXOs containing a particular asset by providing `asset`, where it is the concatenation of policy ID and asset.
@@ -202,37 +202,55 @@ Optionally, you can filter UTXOs containing a particular asset by providing `ass
202202
await fetchAddressUTxOs(address: string, asset?: string)
203203
```
204204

205-
206-
## Fetch Protocol Parameters
205+
### Fetch Protocol Parameters
207206

208207
Fetch the latest protocol parameters.
209208

210209
```tsx
211-
await provider.fetchProtocolParameters()
210+
await provider.fetchProtocolParameters();
212211
```
213212

214213
Optionally, you can provide an epoch number to fetch the protocol parameters of that epoch.
215214

216-
217-
## Fetch UTxOs
215+
### Fetch UTxOs
218216

219217
Get UTxOs for a given hash.
220218

221219
```tsx
222-
await provider.fetchUTxOs('dfd2a2616e6154a092807b1ceebb9ddcadc0f22cf5c8e0e6b0757815083ccb70')
220+
await provider.fetchUTxOs("txHash");
223221
```
224222

225223
Optionally, you can specify the index of the index output.
226224

227225
```tsx
228-
await provider.fetchUTxOs('hash_here', 0)
226+
await provider.fetchUTxOs("txHash", 0);
229227
```
230228

229+
### Listens for new messages from Hydra node
231230

232-
## Submit Transaction
231+
Listens for new messages from Hydra node. The callback function will be called with the message as the only argument. Check <Link href="https://hydra.family/head-protocol/api-reference">all events emitted</Link> by the Hydra node.
232+
233+
```tsx
234+
provider.onMessage((message) => {
235+
console.log("HydraProvider received message", message);
236+
// do something with the message
237+
});
238+
```
239+
240+
The callback function is typed, so you can access the message properties directly.
241+
242+
```tsx
243+
provider.onMessage((message) => {
244+
if (message.tag === "Greetings") {
245+
console.log("message.snapshotUtxo", message.snapshotUtxo);
246+
}
247+
});
248+
```
249+
250+
### Submit Transaction
233251

234252
Submit a serialized transaction to the network.
235253

236254
```tsx
237255
await provider.submitTx(signedTx);
238-
```
256+
```

0 commit comments

Comments
 (0)