You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/content/docs/providers/hydra.mdx
+94-76Lines changed: 94 additions & 76 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
title: "Hydra Provider (beta)"
3
3
desceription: "Layer 2 scaling solution for Cardano that increases transaction throughput and ensures cost efficiency while maintaining security."
4
4
---
5
+
5
6
importLinkfrom"fumadocs-core/link";
6
7
7
8
The <Linkhref="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";
13
14
14
15
// Hydra Head URL and PORT: e.g. http://123.45.67.890:4001
15
16
16
-
const provider =newHydraProvider('<URL>');
17
-
awaitprovider.connect();
17
+
const provider =newHydraProvider("<httpUrl>");
18
18
```
19
19
20
+
## connect
20
21
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..
24
23
25
24
```tsx
26
25
awaitprovider.connect();
27
26
```
28
27
28
+
## disconnect
29
+
30
+
Closes the active connection to a Hydra Head. This is typically managed through the HydraProvider.
29
31
30
-
## Initializes a new Hydra Head
32
+
Parameter (Optional)
31
33
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).
33
35
34
36
```tsx
35
-
awaitprovider.init();
37
+
// Disconnect with default timeout (5 minutes)
38
+
awaitdisconnect(timeout);
39
+
40
+
// Disconnect with custom timeout (e.g., 10 minutes)
41
+
awaitdisconnect(10*60*1000);
36
42
```
37
43
44
+
## Hydra commands APIs
38
45
39
-
##Commit to Hydra Head
46
+
### Initialize
40
47
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.
42
50
43
51
```tsx
44
-
// Params: CommitUtxo, KeyToSign
45
-
awaitinstance.commit("", undefined);
52
+
awaitprovider.init();
46
53
```
47
54
55
+
### Abort
48
56
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`.
52
59
53
60
```tsx
54
61
awaitprovider.abort();
55
62
```
56
63
64
+
### Commit
57
65
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).
59
68
60
-
Submit a transaction through the head. Note that the transaction is only broadcast if well-formed and valid.
69
+
```tsx
70
+
awaitinstance.commitFunds(txHash, outputIndex);
71
+
```
61
72
62
-
You can also the `await provider.submitTx(signedTx)` method to submit a signed transaction.
73
+
### New Transaction
63
74
75
+
Submit a transaction through the head. Note that the transaction is only broadcast if well-formed and valid.
64
76
The `newTx` method accepts the following arguments:
65
77
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
+
66
84
```tsx
67
-
asyncnewTx(
68
-
cborHex: string,
69
-
type:
70
-
|"Tx ConwayEra"
71
-
|"Unwitnessed Tx ConwayEra"
72
-
|"Witnessed Tx ConwayEra",
73
-
description="",
74
-
txId?:string
75
-
)
85
+
asyncnewTx({
86
+
cborHex: "<unsignedTx>",
87
+
description: "commit tx",
88
+
type: "Tx ConwayEra",
89
+
})
90
+
76
91
```
77
92
78
93
Here is an example of how to create a transaction using the Hydra provider, Mesh wallet and Mesh transaction builder:
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.
126
139
127
140
The decommit method accepts the following arguments:
128
141
129
142
```tsx
130
-
asyncdecommit(
131
-
cborHex: string,
132
-
type:
133
-
|"Tx ConwayEra"
134
-
|"Unwitnessed Tx ConwayEra"
135
-
|"Witnessed Tx ConwayEra",
136
-
description="",
137
-
)
143
+
asyncdecommit({
144
+
cborHex: "<unsignedTx>",
145
+
description: "commit tx",
146
+
type: "Tx ConwayEra"
147
+
})
138
148
```
139
149
140
-
141
-
## Close Hydra Head
150
+
### Close
142
151
143
152
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.
144
153
145
154
```tsx
146
155
awaitprovider.close();
147
156
```
148
157
158
+
### Contest
149
159
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.
153
162
154
163
```tsx
155
164
awaitprovider.contest();
156
165
```
157
166
167
+
### Fanout
158
168
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.
162
170
163
171
```tsx
164
172
awaitprovider.fanout();
165
173
```
166
174
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 <Linkhref="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.
Optionally, you can specify the index of the index output.
226
224
227
225
```tsx
228
-
awaitprovider.fetchUTxOs('hash_here', 0)
226
+
awaitprovider.fetchUTxOs("txHash", 0);
229
227
```
230
228
229
+
### Listens for new messages from Hydra node
231
230
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 <Linkhref="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.
0 commit comments