SDK for wallet integration with Hydra
Why
We would like to enable users and applications hosted in Hydra head (i.e. in the L2) to perform typical operations as in a web3 applications, such as perform connecting a wallet, query balance and submit transactions to spend things. Currently, the only way to perform such operations is through low level interactions with the Hydra node's API and no easy way for developers of web based applications to implement these.
What
Within this feature we want to take first step in this direction and focus on the interaction with UTxO one owns in an already open Hydra Head.
-
Extend
MeshJSto support interacting with the hydra-node directly to build transactions- This requires an open Hydra head
- The SDK needs to be provided with connection info to a
hydra-node - Query the UTXO set of a head
- Construct and submit transactions into the head (L2 cardano transactions via
NewTx)
-
~~Extend Nami (or an other straightforward) with this SDK to perform the operations mentioned above.~~
-
Create a minimalistic web page, that shows balance in a head and can construct & sign a transaction using a CIP-30 connected wallet.
-
Update Hydraw to not need the backend component
-
Out of scope: Integrated experience where the wallet knows about the Hydra head(s).
How
- Might want to see whether someone else isn't doing this already
- Hacked together prototype for a lucid provider in hydra-doom: https://github.com/cardano-scaling/hydra-doom/blob/main/src/lucid-provider-hydra.ts
- Another stab at a websocket connection we took on hydra-poll: https://github.com/cardano-scaling/hydra-poll/tree/main/src/lib/hydra-ws
Open questions
- How exactly are we pointing to a
hydra-node? - Discover hydra heads / nodes for a head?
@colll78 @Quantumplation
Hydra Provider beta released!
A minimal example of how to build transaction, sign and submit in Hydra.
import { HydraProvider } from "@meshsdk/hydra";
import { BlockfrostProvider } from "@meshsdk/core";
const blockfrostProvider = new BlockfrostProvider('<Your-API-Key>');
const hydraProvider = new HydraProvider('<URL>');
await hydraProvider.connect();
const wallet = new MeshWallet({
networkId: 0,
key: {
type: "cli",
payment: key,
},
fetcher: blockfrostProvider,
submitter: blockfrostProvider,
});
const pp = await hydraProvider.fetchProtocolParameters();
const utxos = await wallet.getUtxos();
const changeAddress = await wallet.changeAddress();
const txBuilder = new MeshTxBuilder({
fetcher: blockfrostProvider,
params: pp,
});
const unsignedTx = await txBuilder
.txOut(
"addr_test1vpd5axpq4qsh8sxvzny49cp22gc5tqx0djf6wmjv5cx7q5qyrzuw8",
[{ unit: "lovelace", quantity: "3000000" }],
)
.changeAddress(changeAddress)
.selectUtxosFrom(utxos)
.complete();
const signedTx = await wallet.signTx(unsignedTx);
const txHash = await wallet.submitTx(signedTx);
console.log("txHash", txHash);
@ch1bo, here is the source for hydra package.
Here are some intro to the structure:
- handles connection
- provider - to talk to node
- instance - contain wallet and blockfrost provider and transaction builder to help user manage hydra nodes and perform commit funds
- useful type definitions based on the official docs
Next, we are currently working on the end-to-end tutorial, imagine the typescript version of this tutorial.
Happy to get comments.
That's perfect @jinglescode! I think this does cover what we intended with this feature.
Maybe we should start a list of known client implementations in the docs to also have a list of tools to update/notify when we need to change the API?
Started a list here: https://github.com/cardano-scaling/hydra/pull/1877
We’ve built a wallet application that can directly interact with a Hydra Head. You can check out the alpha version here: https://alpha.hydrawallet.app — it even includes a simple explorer to inspect transactions inside a head (https://explorer.hydrawallet.app).
By the way, we’re also working on an SDK for Browser Dapp to make interacting with hydra-node much easier. Feel free to support or follow the project here: https://hydrasdk.com
I'm going to close this one as basically "completed"; even though we haven't achieved the specific deliverables, I think the moral of this issue is provided by, at least, the hydra-sdk and meshjs providers.
I think we can re-submit a similar issue if we have something more specific we would like to achieve here.
Thanks everyone!