evm-contracts-tools 0.0.26 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/contract-get CHANGED
@@ -42,15 +42,20 @@ const
42
42
  require(
43
43
  "crash-js");
44
44
  /* global
45
- _file_read */
45
+ _cmdline_check */
46
46
  const
47
47
  _cmdline_check =
48
48
  _libcrash._cmdline_check;
49
49
  /* global
50
- _file_read */
50
+ _dirname */
51
51
  const
52
52
  _dirname =
53
53
  _libcrash._dirname;
54
+ /* global
55
+ _file_exists */
56
+ const
57
+ _file_exists =
58
+ _libcrash._file_exists;
54
59
  /* global
55
60
  _file_read */
56
61
  const
@@ -249,7 +254,26 @@ async function
249
254
  _contract_address,
250
255
  _contract_compiler_output_path) {
251
256
  let
252
- _contract;
257
+ _contract,
258
+ _msg;
259
+ if ( typeof(
260
+ _contract_compiler_output_path) == "undefined" ||
261
+ _contract_compiler_output_path == "" ) {
262
+ _msg =
263
+ `No contract compiler output path given in input.`;
264
+ _msg_error(
265
+ _msg,
266
+ 1);
267
+ }
268
+ if ( ! _file_exists(
269
+ _contract_compiler_output_path) ) {
270
+ _msg =
271
+ `No contract compiler output found ` +
272
+ `at path '${_contract_compiler_output_path}'.`;
273
+ _msg_error(
274
+ _msg,
275
+ 1);
276
+ }
253
277
  const
254
278
  _contract_compiler_output =
255
279
  _file_read(
@@ -248,6 +248,91 @@ function
248
248
  "ether");
249
249
  }
250
250
 
251
+ async function
252
+ _price_gas_auto_detect(
253
+ _target_network,
254
+ _api_key_path,
255
+ _measure_unit,
256
+ _price_gas) {
257
+ let
258
+ _gas_fee,
259
+ _fee_priority,
260
+ _msg,
261
+ _price_feasible_retries_max,
262
+ _price_gas_transaction_get_args,
263
+ _price_gas_transaction_get_selection_mode,
264
+ _price_gas_transaction_get_retries_max;
265
+ _msg =
266
+ `Auto-detecting gas price.`;
267
+ _msg_info(
268
+ _msg);
269
+ const
270
+ _retries_max =
271
+ 3;
272
+ _price_feasible_retries_max =
273
+ _retries_max;
274
+ _price_gas_transaction_get_selection_mode =
275
+ _price_gas;
276
+ _price_gas_transaction_get_retries_max =
277
+ _retries_max;
278
+ _price_gas_transaction_get_args = [
279
+ _target_network,
280
+ _price_gas_transaction_get_selection_mode,
281
+ _api_key_path,
282
+ _measure_unit,
283
+ "", // wallet seed
284
+ "", // target address,
285
+ "price", // output type
286
+ "", // output file
287
+ _price_gas_transaction_get_retries_max
288
+ ];
289
+ _price_gas = await
290
+ _price_gas_transaction_get.apply(
291
+ null,
292
+ _price_gas_transaction_get_args);
293
+ _price_gas_transaction_get_args = [
294
+ _target_network,
295
+ _price_gas_transaction_get_selection_mode,
296
+ _api_key_path,
297
+ _measure_unit,
298
+ "", // wallet seed
299
+ "", // target address,
300
+ "fee", // output type
301
+ "", // output file
302
+ _price_gas_transaction_get_retries_max
303
+ ];
304
+ _gas_fee = await
305
+ _price_gas_transaction_get.apply(
306
+ null,
307
+ _price_gas_transaction_get_args);
308
+ _price_gas_transaction_get_args = [
309
+ _target_network,
310
+ _price_gas_transaction_get_selection_mode,
311
+ _api_key_path,
312
+ _measure_unit,
313
+ "", // wallet seed
314
+ "", // target address,
315
+ "priority", // output type
316
+ "", // output file
317
+ _price_gas_transaction_get_retries_max
318
+ ];
319
+ _fee_priority = await
320
+ _price_gas_transaction_get.apply(
321
+ null,
322
+ _price_gas_transaction_get_args);
323
+ _msg =
324
+ `Got gas price '${_price_gas}' ` +
325
+ `${_measure_unit} with '${_gas_fee}' ` +
326
+ `'${_measure_unit}' with priority fee ` +
327
+ `'${_fee_priority}' '${_measure_unit}' from rpc ` +
328
+ `'${_target_network}' using ` +
329
+ `selection mode ` +
330
+ `'${_price_gas_transaction_get_selection_mode}'.`;
331
+ _msg_info(
332
+ _msg);
333
+ return _price_gas;
334
+ }
335
+
251
336
  async function
252
337
  _contract_call_dynamic(
253
338
  _call_timeout,
@@ -263,7 +348,8 @@ async function
263
348
  _contract_bytecode_path,
264
349
  _contract_compiler_output_path,
265
350
  _contract_method,
266
- _method_args) {
351
+ _method_args,
352
+ _verbose) {
267
353
  let
268
354
  _amount,
269
355
  _contract,
@@ -304,73 +390,12 @@ async function
304
390
  if ( _price_gas == "auto" ||
305
391
  _price_gas == "fast" ||
306
392
  _price_gas == "nextblock" ) {
307
- _msg =
308
- `Auto-detecting gas price.`;
309
- _msg_info(
310
- _msg);
311
- _price_gas_transaction_get_selection_mode =
312
- _price_gas;
313
- _retries_max =
314
- 3;
315
- _price_feasible_retries_max =
316
- _retries_max;
317
- _price_gas_transaction_get_retries_max =
318
- _retries_max;
319
- _price_gas_transaction_get_args = [
320
- _target_network,
321
- _price_gas_transaction_get_selection_mode,
322
- _api_key_path,
323
- _measure_unit,
324
- "", // wallet seed
325
- "", // target address,
326
- "price", // output type
327
- "", // output file
328
- _price_gas_transaction_get_retries_max
329
- ];
330
- _price_gas = await
331
- _price_gas_transaction_get.apply(
332
- null,
333
- _price_gas_transaction_get_args);
334
- _price_gas_transaction_get_args = [
335
- _target_network,
336
- _price_gas_transaction_get_selection_mode,
337
- _api_key_path,
338
- _measure_unit,
339
- "", // wallet seed
340
- "", // target address,
341
- "fee", // output type
342
- "", // output file
343
- _price_gas_transaction_get_retries_max
344
- ];
345
- _gas_fee = await
346
- _price_gas_transaction_get.apply(
347
- null,
348
- _price_gas_transaction_get_args);
349
- _price_gas_transaction_get_args = [
350
- _target_network,
351
- _price_gas_transaction_get_selection_mode,
352
- _api_key_path,
353
- _measure_unit,
354
- "", // wallet seed
355
- "", // target address,
356
- "priority", // output type
357
- "", // output file
358
- _price_gas_transaction_get_retries_max
359
- ];
360
- _fee_priority = await
361
- _price_gas_transaction_get.apply(
362
- null,
363
- _price_gas_transaction_get_args);
364
- _msg =
365
- `Got gas price '${_price_gas}' ` +
366
- `${_measure_unit} with '${_gas_fee}' ` +
367
- `'${_measure_unit}' with priority fee ` +
368
- `'${_fee_priority}' '${_measure_unit}' from rpc ` +
369
- `'${_target_network}' using ` +
370
- `selection mode ` +
371
- `'${_price_gas_transaction_get_selection_mode}'.`;
372
- _msg_info(
373
- _msg);
393
+ _price_gas =
394
+ _price_gas_auto_detect(
395
+ _target_network,
396
+ _api_key_path,
397
+ _measure_unit,
398
+ _price_gas);
374
399
  }
375
400
  else {
376
401
  _msg =
@@ -387,7 +412,7 @@ async function
387
412
  0;
388
413
  }
389
414
  _msg_value =
390
- Number(
415
+ BigInt(
391
416
  _msg_value);
392
417
  if ( typeof(
393
418
  _call_timeout) === "undefined" ||
@@ -402,6 +427,18 @@ async function
402
427
  Number(
403
428
  _call_timeout);
404
429
  }
430
+ if ( typeof(
431
+ _measure_unit) === "undefined" ||
432
+ _measure_unit == "" ) {
433
+ _measure_unit =
434
+ "wei";
435
+ }
436
+ if ( typeof(
437
+ _verbose) === "undefined" ||
438
+ _verbose == "" ) {
439
+ _verbose =
440
+ "n";
441
+ }
405
442
  _contract_get_opts = [
406
443
  _wallet_seed,
407
444
  _wallet_password,
@@ -516,7 +553,7 @@ async function
516
553
  _price_gas_transaction_get.apply(
517
554
  null,
518
555
  _price_gas_transaction_get_args);
519
- }
556
+ }
520
557
  }
521
558
  if ( _price_feasible_retries_max < _price_feasible_retries ) {
522
559
  _msg =
@@ -619,15 +656,21 @@ async function
619
656
  null,
620
657
  _method_args)
621
658
  }
622
- if ( _tx == undefined ) {
659
+ if ( typeof(
660
+ _tx) == "undefined" ) {
623
661
  _msg = {
624
662
  "code":
625
- 444444,
663
+ 444444,
626
664
  "message":
627
665
  "Transaction response undefined." };
628
666
  throw _msg;
629
667
  }
630
- if ( quiet == "n" ) {
668
+ _msg =
669
+ `Transaction no. '${_tx.nonce}' ` +
670
+ `sent to network.`;
671
+ _msg_info(
672
+ _msg);
673
+ if ( _verbose == "y" ) {
631
674
  console.log(
632
675
  _tx);
633
676
  }
@@ -638,7 +681,8 @@ async function
638
681
  } catch (
639
682
  _error) {
640
683
  if ( "code" in _error ) {
641
- if ( _error["code"] == -32010 ) {
684
+ if ( _error[
685
+ "code"] == -32010 ) {
642
686
  _msg_info(
643
687
  _error[
644
688
  "message"]);
@@ -662,7 +706,8 @@ async function
662
706
  _msg);
663
707
  throw _error;
664
708
  };
665
- return _receipt;
709
+ return [ _tx,
710
+ _receipt];
666
711
  }
667
712
 
668
713
  async function
@@ -682,10 +727,13 @@ async function
682
727
  _contract_compiler_output_path,
683
728
  _contract_method,
684
729
  _method_args,
685
- _output_file) {
730
+ _output_file,
731
+ _verbose) {
686
732
  let
687
733
  _msg,
734
+ _receipt,
688
735
  _tx,
736
+ _tx_cost,
689
737
  _contract_call_dynamic_opts,
690
738
  _wallet_path_list,
691
739
  _wallet_path;
@@ -736,7 +784,7 @@ async function
736
784
  0;
737
785
  }
738
786
  _msg_value =
739
- Number(
787
+ BigInt(
740
788
  _msg_value);
741
789
  if ( typeof(
742
790
  _measure_unit) === undefined ||
@@ -771,6 +819,12 @@ async function
771
819
  _msg_info_wallet_selected(
772
820
  _wallet_path);
773
821
  }
822
+ if ( typeof(
823
+ _verbose) === "undefined" ||
824
+ _verbose == "" ) {
825
+ _verbose =
826
+ "n";
827
+ }
774
828
  _contract_call_dynamic_opts = [
775
829
  _call_timeout,
776
830
  _wallet_seed,
@@ -791,36 +845,73 @@ async function
791
845
  1;
792
846
  while ( _attempt <= _retries_max ) {
793
847
  try {
794
- _tx =
848
+ [ _tx,
849
+ _receipt ] =
795
850
  await _contract_call_dynamic.apply(
796
851
  null,
797
852
  _contract_call_dynamic_opts);
798
- if ( _tx == undefined ) {
853
+ if ( typeof(
854
+ _receipt) == "undefined" ) {
799
855
  _msg_error_transaction_undefined(
800
856
  _attempt);
801
- throw "Transaction undefined."
857
+ _msg =
858
+ "No receipt, transaction may have failed.";
859
+ throw _msg;
802
860
  }
803
- else if ( _tx != undefined ) {
804
- if ( quiet == "n" ) {
861
+ else if ( typeof(
862
+ _receipt) != "undefined" ) {
863
+ _msg =
864
+ `Transaction no. '${_tx.nonce}'.`;
865
+ _msg_info(
866
+ _msg);
867
+ if ( _verbose == "y" ) {
868
+ _msg =
869
+ "Transaction response:";
870
+ _msg_info(
871
+ _msg);
805
872
  console.log(
806
873
  _tx);
874
+ _msg =
875
+ "Transaction receipt:";
876
+ _msg_info(
877
+ _msg);
878
+ console.log(
879
+ _receipt);
807
880
  }
808
- if ( _tx.hash != undefined ) {
881
+ if ( _receipt.hash != undefined ) {
882
+ _msg =
883
+ `Transaction hash: '${_receipt.hash}'.`;
884
+ _msg_info(
885
+ _msg);
886
+ _tx_cost =
887
+ _receipt[
888
+ "gasUsed"] *
889
+ _receipt[
890
+ "gasPrice"];
891
+ if ( _measure_unit == "ether" ) {
892
+ _tx_cost =
893
+ _wei_to_ether(
894
+ _tx_cost);
895
+ }
809
896
  _msg =
810
- "Transaction sent.";
897
+ `Transaction cost: '${_tx_cost}'.`;
811
898
  _msg_info(
812
899
  _msg);
813
900
  break;
814
901
  }
815
- else if ( _tx.hash == undefined ) {
902
+ else if ( _receipt.hash == undefined ) {
816
903
  _msg_error_transaction_failed(
817
904
  _attempt);
818
- throw "Transaction hash undefined."
905
+ _msg =
906
+ "Transaction hash undefined.";
907
+ throw _msg;
819
908
  }
820
909
  else {
821
- _msg_error_transaction_failed(
822
- _attempt);
823
- throw "Unknown transaction error."
910
+ _msg_error_transaction_failed(
911
+ _attempt);
912
+ _msg =
913
+ "Unknown transaction error.";
914
+ throw _msg;
824
915
  }
825
916
  }
826
917
  } catch (
@@ -838,9 +929,12 @@ async function
838
929
  }
839
930
  }
840
931
  if ( _attempt > _retries_max ) {
841
- throw "Maximum number of retries reached.";
932
+ _msg =
933
+ "Maximum number of retries reached.";
934
+ throw _msg;
842
935
  }
843
- return _tx;
936
+ return [_tx,
937
+ _receipt ];
844
938
  }
845
939
 
846
940
  function
@@ -891,32 +985,48 @@ function
891
985
  " [method-args]",
892
986
  "",
893
987
  "Args:",
988
+ "",
894
989
  " <quiet> Can be 'y' or 'n'",
895
990
  " Default: y",
991
+ "",
896
992
  " <retries-max> Maximum number of retries before",
897
993
  " failing.",
994
+ "",
898
995
  " <call-timeout> How many milliseconds to wait for a return",
899
996
  " before declaring the call failed.",
997
+ "",
900
998
  " <wallet-seed> Path of the file containing",
901
999
  " the seed phrase.",
1000
+ "",
902
1001
  " <wallet-password> Password of the wallet.",
1002
+ "",
903
1003
  " <api-key-path> Path of the API key for the",
904
1004
  " contract ABI provider service.",
1005
+ "",
905
1006
  " <target-network> Network on which the contract",
906
1007
  " resides.",
1008
+ "",
907
1009
  " <price-gas> Gas price for the transaction.",
1010
+ "",
908
1011
  " <msg-value> How much <measure-unit> attach",
909
1012
  " to the transaction.",
910
- " Default: 0",
1013
+ ` Default: ${msg_value}`,
1014
+ "",
911
1015
  " <measure-unit> Measure unit for the transaction",
912
1016
  " value. It can be 'wei' or 'ether'",
913
1017
  ` Default: ${measure_unit}`,
1018
+ "",
914
1019
  " <contract-address> Address of the contract.",
1020
+ "",
915
1021
  " <contract-abi_path> Contract ABI path.",
1022
+ "",
916
1023
  " <contract-bytecode-path> Path for the contract bytecode.",
1024
+ "",
917
1025
  " <contract-compiler-output-path> Path for the contract compiler",
918
1026
  " output path (the hardhat artifact).",
1027
+ "",
919
1028
  " <contract-method> Contract method to execute.",
1029
+ "",
920
1030
  " [method-args] Arguments to pass to the method.",
921
1031
  "",
922
1032
  " Options:",
@@ -1077,8 +1187,31 @@ function
1077
1187
  }
1078
1188
  }
1079
1189
 
1190
+ async function
1191
+ _contract_run_cmdline(
1192
+ app_opts) {
1193
+ let
1194
+ _receipt,
1195
+ _tx;
1196
+ [ _tx,
1197
+ _receipt ] =
1198
+ await _contract_run.apply(
1199
+ null,
1200
+ app_opts);
1201
+ _msg =
1202
+ "Transaction response:"
1203
+ console.log(
1204
+ _tx);
1205
+ _msg =
1206
+ "Transaction receipt:"
1207
+ console.log(
1208
+ _receipt);
1209
+ }
1210
+
1080
1211
  if ( _cmdline_check(
1081
- "evm-contract-call-dynamic") ) {
1212
+ "evm-contract-call-dynamic") ||
1213
+ _cmdline_check(
1214
+ "contract-run") ) {
1082
1215
  _global_variables();
1083
1216
  _cmdline_parse();
1084
1217
  _config_show();
@@ -1100,8 +1233,7 @@ if ( _cmdline_check(
1100
1233
  contract_method,
1101
1234
  method_args
1102
1235
  ];
1103
- _contract_run.apply(
1104
- null,
1236
+ _contract_run_cmdline(
1105
1237
  app_opts);
1106
1238
  }
1107
1239
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  { "name": "evm-contracts-tools",
2
2
  "version":
3
- "0.0.26",
3
+ "0.0.28",
4
4
  "description":
5
5
  "JavaScript programs and libraries to enable seamless development of native computer applications designed to interact with Ethereum Virtual Machine-compatible networks.",
6
6
  "funding": {
@@ -86,7 +86,7 @@
86
86
  "evm-transactions-tools":
87
87
  "^0.0.9",
88
88
  "evm-wallet.js":
89
- "^0.0.40",
89
+ "^0.0.42",
90
90
  "libevm":
91
91
  "^0.0.20",
92
92
  "yargs":
@@ -94,9 +94,9 @@
94
94
  },
95
95
  "overrides": {
96
96
  "evm-contracts-tools":
97
- "^0.0.24",
97
+ "^0.0.27",
98
98
  "evm-wallet.js":
99
- "^0.0.40"
99
+ "^0.0.42"
100
100
  },
101
101
  "type":
102
102
  "commonjs",