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