Skip to content

Commit 6f031c4

Browse files
committed
Doc: Add common kuber functions
1 parent a2f11be commit 6f031c4

19 files changed

+382
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ async function main() {
3737
}
3838

3939
main();
40+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ async function main() {
5050
}
5151

5252
main();
53+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ async function main() {
3737
}
3838

3939
main();
40+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ async function main() {
4949
}
5050

5151
main();
52+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ async function main() {
3737
}
3838

3939
main();
40+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ async function main() {
5050
}
5151

5252
main();
53+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ async function main() {
3737
}
3838

3939
main();
40+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ async function main() {
3737
}
3838

3939
main();
40+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ async function main() {
3030
}
3131

3232
main();
33+
```
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
sidebar_position: 5
3+
sidebar_label: buildAndSignWithWallet
4+
---
5+
6+
# buildAndSignWithWallet
7+
8+
`buildAndSignWithWallet` is an asynchronous function that builds a transaction, automatically adds UTxOs from the wallet, and then signs the transaction using the provided CIP-30 compatible wallet.
9+
10+
## Function Signature
11+
12+
```typescript
13+
async buildAndSignWithWallet(
14+
cip30OrProvider: Cip30 | Cip30Provider,
15+
buildRequest: Record<string, any>,
16+
autoAddCollateral = false,
17+
estimatedSpending?: number | bigint,
18+
): Promise<SignTxResult>
19+
```
20+
21+
## Parameters
22+
23+
- `cip30OrProvider`: A CIP-30 compatible wallet instance or provider.
24+
- `buildRequest`: An object following Kuber's transaction builder JSON specification. For a comprehensive reference on transaction builder fields and their usage, please refer to the [KuberIDE TxBuilder Object Reference](https://kuberide.com/kuber/docs/tx-builder-reference).
25+
- `autoAddCollateral`: An optional `boolean` indicating whether to automatically add collateral from the provider. Defaults to `false`.
26+
- `estimatedSpending`: An optional `number` or `bigint` representing the estimated amount of Lovelace to be spent.
27+
28+
## Returns
29+
30+
A `Promise` that resolves to a `SignTxResult` object, containing the signed transaction.
31+
32+
## Example
33+
34+
```typescript
35+
import { KuberHydraApiProvider } from "kuber-client";
36+
import { loadCrypto, Ed25519Key } from "libcardano";
37+
import { ShelleyWallet, Cip30ShelleyWallet } from "libcardano-wallet";
38+
import { readFileSync } from "fs";
39+
40+
async function main() {
41+
await loadCrypto();
42+
43+
const hydra = new KuberHydraApiProvider("http://localhost:8081"); // Replace with your Hydra API URL
44+
45+
// Load test wallet signing key
46+
const testWalletSigningKey = await Ed25519Key.fromCardanoCliJson(
47+
JSON.parse(readFileSync(process.env.HOME + "/.cardano/preview/hydra-0/credentials/funds.sk", "utf-8")),
48+
);
49+
50+
// Setup libcardano crypto and Shelley wallet
51+
const shelleyWallet = new ShelleyWallet(testWalletSigningKey);
52+
const cip30Wallet = new Cip30ShelleyWallet(hydra, hydra, shelleyWallet, 0);
53+
const walletAddress = (await cip30Wallet.getChangeAddress()).toBech32();
54+
55+
const transaction = {
56+
outputs: [{ address: walletAddress, value: "1_000_000" }], // Sending 1 ADA
57+
changeAddress: walletAddress,
58+
};
59+
60+
try {
61+
console.log("Building and signing transaction with wallet...");
62+
const signedTx = await hydra.buildAndSignWithWallet(cip30Wallet, transaction);
63+
console.log("Signed transaction:", signedTx);
64+
console.log("Signed CBOR Hex:", signedTx.updatedTxBytes.toString('hex'));
65+
} catch (error) {
66+
console.error("Error building and signing transaction with wallet:", error);
67+
}
68+
}
69+
70+
main();

0 commit comments

Comments
 (0)