@@ -14,11 +14,11 @@ The `HydraInstance` is intialized together with `HydraProvider`, for accessing o
1414``` tsx
1515import { HydraInstance , HydraProvider } from " @meshsdk/hydra" ;
1616
17- const hydraProvider = new HydraProvider ({
17+ const provider = new HydraProvider ({
1818 httpUrl: " <hydra-API-URL>" ,
1919});
2020
21- const hydraInstance = new HydraInstance ({
21+ const instance = new HydraInstance ({
2222 provider: hydraProvider ,
2323 fetcher: " <blockchainProvider>" ,
2424 submitter: " <blockchainProvider>" ,
@@ -31,7 +31,7 @@ If you don't want to commit any funds and only want to receive on layer 2, you c
3131to open the head
3232
3333``` tsx
34- const commit = await hydraInstance .commitEmpty ();
34+ const commit = await instance .commitEmpty ();
3535const submitTx = await wallet .submitTx (commit );
3636console .log (" submitTx" , submitTx );
3737```
@@ -47,15 +47,15 @@ Commits funds to the Hydra head by selecting specific UTxOs to make available on
4747** Returns:** The transaction CBOR hex ready to be partially signed
4848
4949``` tsx
50- await commitFunds (txHash : string , outputIndex : number )
50+ await instance . commitFunds (txHash : string , outputIndex : number )
5151```
5252
5353``` tsx
5454const txHash =
5555 " 00000000000000000000000000000000000000000000000000000000000000000" ;
5656const outputIndex = 0 ;
5757
58- const commitTx = await hydraInstance .commitFunds (txHash , outputIndex );
58+ const commitTx = await instance .commitFunds (txHash , outputIndex );
5959const signedTx = await wallet .signTx (commitTx , true );
6060const commitTxHash = await wallet .submitTx (signedTx );
6161```
@@ -72,15 +72,15 @@ This is useful for advanced use cases such as commiting `scriptUTxOs`.
7272- ` hydraTransaction `
7373
7474``` tsx
75- await hydraInstance .commitBlueprint (" txHash" , outputIndex , {
75+ await instance .commitBlueprint (" txHash" , outputIndex , {
7676 cborHex: " <unsignedTx>" ,
7777 description: " commit tx" ,
7878 type: " Tx ConwayEra" ,
7979});
8080```
8181
8282``` tsx
83- const commitTx = await hydraInstance .commitBlueprint (txHash , outputIndex , {
83+ const commitTx = await instance .commitBlueprint (txHash , outputIndex , {
8484 cborHex: " <unsignedTx>" ,
8585 description: " commit tx" ,
8686 type: " Tx ConwayEra" ,
@@ -97,20 +97,19 @@ The time it takes for it top be added after commit depends on the `hydra-node` c
9797To read more on incremental commit, see [ the Hydra documentation] ( https://hydra.family/head-protocol/docs/how-to/incremental-commit ) .
9898
9999### incrementalCommitFunds
100+
100101``` tsx
101- await incrementalCommitFunds (txHash : string , outputIndex : number )
102+ await instance . incrementalCommitFunds (txHash : string , outputIndex : number )
102103```
104+
103105### incrementalBlueprintCommit
106+
104107``` tsx
105- await incrementalBlueprintCommit (
106- txHash ,
107- outputIndex ,
108- {
109- cborHex: " unsignedTx" ,
110- description: " commit tx" ,
111- type: " Tx ConwayEra" ,
112- }
113- )
108+ await instance .incrementalBlueprintCommit (txHash , outputIndex , {
109+ cborHex: " unsignedTx" ,
110+ description: " commit tx" ,
111+ type: " Tx ConwayEra" ,
112+ });
114113```
115114
116115## Basic Workflow
@@ -125,45 +124,65 @@ const provider = new HydraProvider({
125124 httpUrl: " http://localhost:4001" ,
126125});
127126
128- const hydraInstance = new HydraInstance ({
127+ const instance = new HydraInstance ({
129128 provider: provider ,
130129 fetcher: " blockchainProvider" ,
131130 submitter: " blockchainProvider" ,
132131});
133132
134133await provider .connect ();
135-
136134await provider .init ();
137135
138- const commitTx = await hydraInstance .commitFunds (txHash , outputIndex );
139- const signedTx = await wallet .signTx (commitTx , true );
140- await wallet .submitTx (signedTx );
136+ provider .onMessage ((message ) => {
137+ const status =
138+ message .tag === " Greetings"
139+ ? { headStatus: message .headStatus }
140+ : { tag: message .tag };
141+ if (
142+ status .tag === " HeadIsInitializing" ||
143+ status .headStatus === " Initializing"
144+ ) {
145+ }
146+ const commitTx = await instance .commitFunds (txHash , outputIndex );
147+ const signedTx = await wallet .signTx (commitTx , true );
148+ await wallet .submitTx (signedTx );
149+ });
141150```
142151
143152### Blueprint Commit
144153
145154``` 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" ,
155+ provider .onMessage ((message ) => {
156+ const status =
157+ message .tag === " Greetings"
158+ ? { headStatus: message .headStatus }
159+ : { tag: message .tag };
160+ if (
161+ status .tag === " HeadIsInitializing" ||
162+ status .headStatus === " Initializing"
163+ ) {
164+ const txBuilder = new MeshTxBuilder ({
165+ submitter: " <blockchainProvider>" ,
166+ fetcher: " <blockchainProvider>" ,
167+ verbose: true ,
168+ });
169+
170+ const unsignedTx = await txBuilder
171+ .txIn (txHash , outputIndex )
172+ .setFee (" 0" )
173+ .changeAddress (address )
174+ .selectUtxosFrom (UTxOs )
175+ .complete ();
176+
177+ const commitTx = await instance .commitBlueprint (txHash , outputIndex , {
178+ type: " Tx ConwayEra" ,
179+ cborHex: unsignedTx ,
180+ description: " Commit Blueprint" ,
181+ });
182+
183+ const signedTx = await wallet .signTx (commitTx );
184+ const commitTxHash = await wallet .submitTx (signedTx );
185+ console .log (commitTxHash );
186+ }
164187});
165-
166- const signedTx = await wallet .signTx (commitTx );
167- const commitTxHash = await wallet .submitTx (signedTx );
168- console .log (commitTxHash );
169188```
0 commit comments