Skip to content

Commit de27f9f

Browse files
authored
Merge pull request #900 from IntersectMBO/cardano-wasm-balancing
Add `estimateMinFee` function to `UnsignedTx`
2 parents 3cb72b5 + 7c9eb4c commit de27f9f

File tree

8 files changed

+2232
-29
lines changed

8 files changed

+2232
-29
lines changed

cardano-wasm/cardano-wasm.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ executable cardano-wasm
3737
ghc-options:
3838
-no-hs-main
3939
-optl-mexec-model=reactor
40-
"-optl-Wl,--strip-all,--export=getApiInfo,--export=newConwayTx,--export=addTxInput,--export=addSimpleTxOut,--export=setFee,--export=signWithPaymentKey,--export=alsoSignWithPaymentKey,--export=txToCbor"
40+
"-optl-Wl,--strip-all,--export=getApiInfo,--export=newConwayTx,--export=addTxInput,--export=addSimpleTxOut,--export=setFee,--export=estimateMinFee,--export=signWithPaymentKey,--export=alsoSignWithPaymentKey,--export=txToCbor"
4141
other-modules:
4242
Cardano.Wasm.Internal.Api.Info
4343
Cardano.Wasm.Internal.Api.Tx

cardano-wasm/example/index.html

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
<html>
2+
23
<body>
3-
<script type="module">
4-
import cardano_api from "./cardano-api.js";
5-
let promise = cardano_api();
6-
async function do_async_work() {
7-
let api = await promise;
8-
console.log("Api object:");
9-
console.log(api);
4+
<script type="module">
5+
import cardano_api from "./cardano-api.js";
6+
let promise = cardano_api();
7+
async function get_protocol_params() {
8+
const response = await fetch("./preview_pparams.json");
9+
return (await response.json());
10+
}
11+
let protocolParams = await get_protocol_params();
12+
async function do_async_work() {
13+
let api = await promise;
14+
console.log("Api object:");
15+
console.log(api);
16+
17+
let emptyTx = await api.newConwayTx();
18+
console.log("UnsignedTx object:");
19+
console.log(emptyTx);
1020

11-
let emptyTx = await api.newConwayTx();
12-
console.log("UnsignedTx object:");
13-
console.log(emptyTx);
21+
let tx = await emptyTx.addTxInput("be6efd42a3d7b9a00d09d77a5d41e55ceaf0bd093a8aa8a893ce70d9caafd978", 0)
22+
.addSimpleTxOut("addr_test1vzpfxhjyjdlgk5c0xt8xw26avqxs52rtf69993j4tajehpcue4v2v", 10_000_000n)
1423

15-
let signedTx = await emptyTx.addTxInput("be6efd42a3d7b9a00d09d77a5d41e55ceaf0bd093a8aa8a893ce70d9caafd978", 0)
16-
.addSimpleTxOut("addr_test1vzpfxhjyjdlgk5c0xt8xw26avqxs52rtf69993j4tajehpcue4v2v", 10_000_000n)
17-
.setFee(2_000_000n)
18-
.signWithPaymentKey("addr_sk1648253w4tf6fv5fk28dc7crsjsaw7d9ymhztd4favg3cwkhz7x8sl5u3ms");
24+
let feeEstimate = await tx.estimateMinFee(protocolParams, 1, 0, 0);
25+
console.log("Estimated fee:");
26+
console.log(feeEstimate);
1927

20-
console.log("SignedTx object:");
21-
console.log(signedTx);
28+
let signedTx = await tx.setFee(feeEstimate)
29+
.signWithPaymentKey("addr_sk1648253w4tf6fv5fk28dc7crsjsaw7d9ymhztd4favg3cwkhz7x8sl5u3ms");
30+
console.log("SignedTx object:");
31+
console.log(signedTx);
2232

23-
let txCbor = await signedTx.txToCbor();
24-
console.log("Tx CBOR:");
25-
console.log(txCbor);
26-
}
27-
do_async_work().then(() => {});
28-
</script>
33+
let txCbor = await signedTx.txToCbor();
34+
console.log("Tx CBOR:");
35+
console.log(txCbor);
36+
}
37+
do_async_work().then(() => { });
38+
</script>
2939
</body>
30-
</html>
40+
41+
</html>

0 commit comments

Comments
 (0)