Skip to content

Commit 3622095

Browse files
committed
Update docs and Readme.
1 parent 66a1fbf commit 3622095

File tree

5 files changed

+100
-5
lines changed

5 files changed

+100
-5
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
sidebar_position: 4
3+
sidebar_label: Minting Native Tokens
4+
---
5+
6+
# Minting Native Tokens
7+
8+
This guide demonstrates how to mint native tokens within an open Hydra Head using the cip30 interface and `KuberHydraApiProvider`.
9+
10+
## Prerequisites
11+
12+
- Node.js environment
13+
- `libcardano` and `libcardano-wallet` installed.
14+
- An active Hydra Head (in "Open" state).
15+
- A configured `KuberHydraApiProvider` instance.
16+
- A minting policy script and its corresponding key hash.
17+
18+
This example demonstrates how to build and submit a transaction that mints native tokens within an open Hydra Head.
19+
20+
```typescript
21+
import { KuberHydraApiProvider } from "kuber-client";
22+
import { Value, Ed25519Key, loadCrypto } from "libcardano";
23+
import { ShelleyWallet, Cip30ShelleyWallet } from "libcardano-wallet";
24+
import { readFileSync } from "fs";
25+
26+
async function runMintNativeTokensExample() {
27+
// Initialize Hydra API Provider (replace with your Hydra node URL)
28+
const hydra = new KuberHydraApiProvider("http://172.31.6.1:8082");
29+
30+
// Load test wallet signing key (used for signing the transaction)
31+
const testWalletSigningKey = await Ed25519Key.fromCardanoCliJson(
32+
JSON.parse(readFileSync(process.env.HOME + "/.cardano/preview/hydra-0/credentials/funds.sk", "utf-8")),
33+
);
34+
35+
// Setup libcardano crypto and Shelley wallet
36+
await loadCrypto();
37+
const shelleyWallet = new ShelleyWallet(testWalletSigningKey);
38+
const cip30Wallet = new Cip30ShelleyWallet(hydra, hydra, shelleyWallet, 0);
39+
const walletAddress = (await cip30Wallet.getChangeAddress()).toBech32();
40+
41+
console.log("Wallet Address:", walletAddress);
42+
43+
// Ensure head is in 'Open' state
44+
const headState = await hydra.queryHeadState();
45+
if (headState.state !== "Open") {
46+
console.log("Head is not in 'Open' state. Please ensure it's in 'Open' state before running this example.");
47+
return;
48+
}
49+
console.log("Hydra Head is Open. Proceeding with minting transaction.");
50+
51+
// Define the minting transaction
52+
// For a comprehensive reference on transaction builder fields, refer to:
53+
// https://kuberide.com/kuber/docs/tx-builder-reference
54+
const mintingTransaction = {
55+
mint: [
56+
{
57+
script: {
58+
type: "sig",
59+
keyHash: shelleyWallet.paymentKey.pkh.toString('hex'),
60+
},
61+
amount: {
62+
Token1: 2,
63+
},
64+
},
65+
],
66+
changeAddress: walletAddress,
67+
};
68+
69+
try {
70+
// Use the buildAndSubmitWithWallet function from KuberProvider to mint tokens
71+
const mintResult = await hydra.buildAndSubmitWithWallet(cip30Wallet, mintingTransaction);
72+
console.log("Minting transaction submitted to Hydra Head. Hash:", mintResult.hash);
73+
console.log("CBOR Hex:", mintResult.cborHex);
74+
} catch (error: unknown) {
75+
if (error instanceof Error) {
76+
console.error("Error building or submitting minting transaction:", error.message);
77+
} else {
78+
console.error("An unknown error occurred:", error);
79+
}
80+
}
81+
}
82+
83+
runMintNativeTokensExample();

docs/docs/hydra-js-client/examples/submitting-hydra-transactions.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ This guide demonstrates how to build and submit transactions within an open Hydr
1414
- An active Hydra Head (in "Open" state).
1515
- A configured `KuberHydraApiProvider` instance.
1616

17+
##### Transaction builder
18+
R efer to the [KuberIDE TxBuilder Object Reference](https://kuberide.com/kuber/docs/tx-builder-reference) for details of all transaction builder properties.
19+
1720
This example demonstrates how to build and submit a simple transaction (sending Lovelace to an address) within an open Hydra Head using the `KuberHydraApiProvider` and a CIP-30 compatible wallet.
1821

1922
```typescript
@@ -48,15 +51,18 @@ async function runBuildAndSubmitTransactionExample() {
4851
console.log("Hydra Head is Open. Proceeding with transaction.");
4952

5053
// Define the transaction outputs
51-
const transaction = {
52-
outputs: [{ address: walletAddress, value: { lovelace: "3000000" } }], // Sending 3 ADA
54+
// For a comprehensive reference on transaction builder fields, refer to:
55+
// https://kuberide.com/kuber/docs/tx-builder-reference
56+
const txBuilder = {
57+
outputs: [{ address: walletAddress, value: "3_000_000" } }], // Sending 3 ADA
5358
changeAddress: walletAddress,
5459
};
5560

5661
try {
5762
// Use the buildAndSubmitWithWallet function from KuberProvider
58-
const submitResult = await hydra.buildAndSubmitWithWallet(cip30Wallet, transaction);
59-
console.log("Transaction submitted to Hydra Head. Result:", submitResult);
63+
const submitResult = await hydra.buildAndSubmitWithWallet(cip30Wallet, txBuilder);
64+
console.log("Transaction submitted to Hydra Head. Hash:", submitResult.hash);
65+
console.log("CBOR Hex:", submitResult.cborHex);
6066

6167
} catch (error: unknown) {
6268
if (error instanceof Error) {

docs/docs/hydra-js-client/submitTx.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ async function main() {
3434
try {
3535
console.log("Submitting transaction...");
3636
const result = await hydra.submitTx(signedCborTx);
37-
console.log("Transaction submitted:", result);
37+
console.log("Transaction submitted. Hash:", result.hash);
38+
console.log("CBOR Hex:", result.cborHex);
3839
} catch (error) {
3940
console.error("Error submitting transaction:", error);
4041
}

docs/sidebars.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const sidebars: SidebarsConfig = {
8888
"hydra-js-client/examples/working-with-wallets",
8989
"hydra-js-client/examples/commiting-utxos-to-hydra",
9090
"hydra-js-client/examples/submitting-hydra-transactions",
91+
"hydra-js-client/examples/minting-native-tokens",
9192
],
9293
},
9394
{

kuber-hydra/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
- [Architecture](https://dquadrant.github.io/kuber/hydra_docusaurus/docs/architecture)
55
- [Getting Started with Kuber-Hydra](https://dquadrant.github.io/kuber/hydra_docusaurus/docs/hydra-js-client/getting-started)
66

7+
8+
### Tests:
9+
- [✅ Passing](https://dquadrant.github.io/kuber/test-reports/hydra/) on v4.0.0
10+
711
## Running Kuber-Hydra
812

913
### With cabal

0 commit comments

Comments
 (0)