@provablehq/sdk 0.8.6 → 0.8.8

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.
@@ -1,4 +1,4 @@
1
- import { PrivateKey, RecordCiphertext, Program, Plaintext, Transaction, Metadata, VerifyingKey, ProvingKey, ProgramManager as ProgramManager$1, RecordPlaintext, verifyFunctionExecution } from '@provablehq/wasm/testnet.js';
1
+ import { PrivateKey, RecordCiphertext, Program, Plaintext, Address, Transaction, Metadata, VerifyingKey, ProvingKey, ProgramManager as ProgramManager$1, RecordPlaintext, verifyFunctionExecution } from '@provablehq/wasm/testnet.js';
2
2
 
3
3
  function logAndThrow(message) {
4
4
  console.error(message);
@@ -37,12 +37,12 @@ async function post(url, options) {
37
37
  *
38
38
  * @param {string} host
39
39
  * @example
40
- * // Connection to a local node
41
- * const localNetworkClient = new AleoNetworkClient("http://localhost:3030");
40
+ * // Connection to a local node.
41
+ * const localNetworkClient = new AleoNetworkClient("http://0.0.0.0:3030", undefined, account);
42
42
  *
43
43
  * // Connection to a public beacon node
44
44
  * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
45
- * const publicnetworkClient = new AleoNetworkClient("http://localhost:3030", undefined, account);
45
+ * const publicNetworkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined, account);
46
46
  */
47
47
  class AleoNetworkClient {
48
48
  host;
@@ -56,15 +56,18 @@ class AleoNetworkClient {
56
56
  else {
57
57
  this.headers = {
58
58
  // This is replaced by the actual version by a Rollup plugin
59
- "X-Aleo-SDK-Version": "0.8.6",
59
+ "X-Aleo-SDK-Version": "0.8.8",
60
60
  };
61
61
  }
62
62
  }
63
63
  /**
64
64
  * Set an account to use in networkClient calls
65
65
  *
66
- * @param {Account} account
66
+ * @param {Account} account Set an account to use for record scanning functions.
67
67
  * @example
68
+ * import { Account, AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
69
+ *
70
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1");
68
71
  * const account = new Account();
69
72
  * networkClient.setAccount(account);
70
73
  */
@@ -85,6 +88,15 @@ class AleoNetworkClient {
85
88
  *
86
89
  * @param {string} host The address of a node hosting the Aleo API
87
90
  * @param host
91
+ *
92
+ * @example
93
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
94
+ *
95
+ * // Create a networkClient that connects to a local node.
96
+ * const networkClient = new AleoNetworkClient("http://0.0.0.0:3030", undefined);
97
+ *
98
+ * // Set the host to a public node.
99
+ * networkClient.setHost("http://api.explorer.provable.com/v1");
88
100
  */
89
101
  setHost(host) {
90
102
  this.host = host + "/testnet";
@@ -92,7 +104,7 @@ class AleoNetworkClient {
92
104
  /**
93
105
  * Fetches data from the Aleo network and returns it as a JSON object.
94
106
  *
95
- * @param url
107
+ * @param url The URL to fetch data from.
96
108
  */
97
109
  async fetchData(url = "/") {
98
110
  try {
@@ -132,8 +144,18 @@ class AleoNetworkClient {
132
144
  * @param {number} maxMicrocredits - The maximum number of microcredits to search for
133
145
  * @param {string[]} nonces - The nonces of already found records to exclude from the search
134
146
  * @param {string | PrivateKey} privateKey - An optional private key to use to find unspent records.
147
+ * @returns {Promise<Array<RecordPlaintext>>} An array of records belonging to the account configured in the network client.
135
148
  *
136
149
  * @example
150
+ * import { Account, AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
151
+ *
152
+ * // Import an account from a ciphertext and password.
153
+ * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
154
+ *
155
+ * // Create a network client.
156
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
157
+ * networkClient.setAccount(account);
158
+ *
137
159
  * // Find specific amounts
138
160
  * const startHeight = 500000;
139
161
  * const amounts = [600000, 1000000];
@@ -324,8 +346,17 @@ class AleoNetworkClient {
324
346
  * @param {number} maxMicrocredits - The maximum number of microcredits to search for
325
347
  * @param {string[]} nonces - The nonces of already found records to exclude from the search
326
348
  * @param {string | PrivateKey} privateKey - An optional private key to use to find unspent records.
349
+ * @returns {Promise<Array<RecordPlaintext>>} An array of unspent records belonging to the account configured in the network client.
327
350
  *
328
351
  * @example
352
+ * import { Account, AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
353
+ *
354
+ * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
355
+ *
356
+ * // Create a network client and set an account to search for records with.
357
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
358
+ * networkClient.setAccount(account);
359
+ *
329
360
  * // Find specific amounts
330
361
  * const startHeight = 500000;
331
362
  * const endHeight = 550000;
@@ -342,7 +373,9 @@ class AleoNetworkClient {
342
373
  /**
343
374
  * Returns the contents of the block at the specified block height.
344
375
  *
345
- * @param {number} blockHeight
376
+ * @param {number} blockHeight - The height of the block to fetch
377
+ * @returns {Promise<BlockJSON>} A javascript object containing the block at the specified height
378
+ *
346
379
  * @example
347
380
  * const block = networkClient.getBlock(1234);
348
381
  */
@@ -358,8 +391,13 @@ class AleoNetworkClient {
358
391
  /**
359
392
  * Returns the contents of the block with the specified hash.
360
393
  *
361
- * @param {string} blockHash
394
+ * @param {string} blockHash The hash of the block to fetch.
395
+ * @returns {Promise<BlockJSON>} A javascript object representation of the block matching the hash.
396
+ *
362
397
  * @example
398
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
399
+ *
400
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
363
401
  * const block = networkClient.getBlockByHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
364
402
  */
365
403
  async getBlockByHash(blockHash) {
@@ -372,12 +410,24 @@ class AleoNetworkClient {
372
410
  }
373
411
  }
374
412
  /**
375
- * Returns a range of blocks between the specified block heights.
413
+ * Returns a range of blocks between the specified block heights. A maximum of 50 blocks can be fetched at a time.
414
+ *
415
+ * @param {number} start Starting block to fetch.
416
+ * @param {number} end Ending block to fetch. This cannot be more than 50 blocks ahead of the start block.
417
+ * @returns {Promise<Array<BlockJSON>>} An array of block objects
376
418
  *
377
- * @param {number} start
378
- * @param {number} end
379
419
  * @example
380
- * const blockRange = networkClient.getBlockRange(2050, 2100);
420
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
421
+ *
422
+ * // Fetch 50 blocks.
423
+ * const (start, end) = (2050, 2100);
424
+ * const blockRange = networkClient.getBlockRange(start, end);
425
+ *
426
+ * let cursor = start;
427
+ * blockRange.forEach((block) => {
428
+ * assert(block.height == cursor);
429
+ * cursor += 1;
430
+ * }
381
431
  */
382
432
  async getBlockRange(start, end) {
383
433
  try {
@@ -390,8 +440,21 @@ class AleoNetworkClient {
390
440
  /**
391
441
  * Returns the deployment transaction id associated with the specified program.
392
442
  *
393
- * @param {Program | string} program
394
- * @returns {TransactionJSON}
443
+ * @param {Program | string} program The name of the deployed program OR a wasm Program object.
444
+ * @returns {Promise<string>} The transaction ID of the deployment transaction.
445
+ *
446
+ * @example
447
+ * import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
448
+ *
449
+ * // Get the transaction ID of the deployment transaction for a program.
450
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
451
+ * const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo");
452
+ *
453
+ * // Get the transaction data for the deployment transaction.
454
+ * const transaction = networkClient.getTransactionObject(transactionId);
455
+ *
456
+ * // Get the verifying keys for the functions in the deployed program.
457
+ * const verifyingKeys = transaction.verifyingKeys();
395
458
  */
396
459
  async getDeploymentTransactionIDForProgram(program) {
397
460
  if (program instanceof Program) {
@@ -406,10 +469,21 @@ class AleoNetworkClient {
406
469
  }
407
470
  }
408
471
  /**
409
- * Returns the deployment transaction associated with a specified program.
472
+ * Returns the deployment transaction associated with a specified program as a JSON object.
410
473
  *
411
- * @param {Program | string} program
412
- * @returns {TransactionJSON}
474
+ * @param {Program | string} program The name of the deployed program OR a wasm Program object.
475
+ * @returns {Promise<Transaction>} JSON representation of the deployment transaction.
476
+ *
477
+ * @example
478
+ * import { AleoNetworkClient, DeploymentJSON } from "@provablehq/sdk/testnet.js";
479
+ *
480
+ * // Get the transaction ID of the deployment transaction for a program.
481
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
482
+ * const transaction = networkClient.getDeploymentTransactionForProgram("hello_hello.aleo");
483
+ *
484
+ * // Get the verifying keys for each function in the deployment.
485
+ * const deployment = <DeploymentJSON>transaction.deployment;
486
+ * const verifyingKeys = deployment.verifying_keys;
413
487
  */
414
488
  async getDeploymentTransactionForProgram(program) {
415
489
  if (program instanceof Program) {
@@ -426,8 +500,21 @@ class AleoNetworkClient {
426
500
  /**
427
501
  * Returns the deployment transaction associated with a specified program as a wasm object.
428
502
  *
429
- * @param {Program | string} program
430
- * @returns {TransactionJSON}
503
+ * @param {Program | string} program The name of the deployed program OR a wasm Program object.
504
+ * @returns {Promise<Transaction>} Wasm object representation of the deployment transaction.
505
+ *
506
+ * @example
507
+ * import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
508
+ *
509
+ * // Get the transaction ID of the deployment transaction for a program.
510
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
511
+ * const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo");
512
+ *
513
+ * // Get the transaction data for the deployment transaction.
514
+ * const transaction = networkClient.getDeploymentTransactionObjectForProgram(transactionId);
515
+ *
516
+ * // Get the verifying keys for the functions in the deployed program.
517
+ * const verifyingKeys = transaction.verifyingKeys();
431
518
  */
432
519
  async getDeploymentTransactionObjectForProgram(program) {
433
520
  try {
@@ -439,9 +526,16 @@ class AleoNetworkClient {
439
526
  }
440
527
  }
441
528
  /**
442
- * Returns the contents of the latest block.
529
+ * Returns the contents of the latest block as JSON.
530
+ *
531
+ * @returns {Promise<BlockJSON>} A javascript object containing the latest block
443
532
  *
444
533
  * @example
534
+ * import { AleoNetworkClient } from "@provablehq/sdk/testnet.js";
535
+ *
536
+ * // Create a network client.
537
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
538
+ *
445
539
  * const latestHeight = networkClient.getLatestBlock();
446
540
  */
447
541
  async getLatestBlock() {
@@ -456,6 +550,16 @@ class AleoNetworkClient {
456
550
  * Returns the latest committee.
457
551
  *
458
552
  * @returns {Promise<object>} A javascript object containing the latest committee
553
+ *
554
+ * @example
555
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
556
+ *
557
+ * // Create a network client.
558
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
559
+ *
560
+ * // Create a network client and get the latest committee.
561
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
562
+ * const latestCommittee = await networkClient.getLatestCommittee();
459
563
  */
460
564
  async getLatestCommittee() {
461
565
  try {
@@ -466,14 +570,20 @@ class AleoNetworkClient {
466
570
  }
467
571
  }
468
572
  /**
469
- * Returns the committe at the specified block height.
470
- *
471
- * @param {number} blockHeight
573
+ * Returns the committee at the specified block height.
472
574
  *
575
+ * @param {number} blockHeight - The height of the block to fetch the committee for
473
576
  * @returns {Promise<object>} A javascript object containing the committee
474
577
  *
475
578
  * @example
476
- * const committee = await networkClient.getCommitteByBlockHeight(1234);
579
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
580
+ *
581
+ * // Create a network client.
582
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
583
+ *
584
+ * // Create a network client and get the committee for a specific block.
585
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
586
+ * const committee = await networkClient.getCommitteeByBlockHeight(1234);
477
587
  */
478
588
  async getCommitteeByBlockHeight(blockHeight) {
479
589
  try {
@@ -486,7 +596,14 @@ class AleoNetworkClient {
486
596
  /**
487
597
  * Returns the latest block height.
488
598
  *
599
+ * @returns {Promise<number>} The latest block height.
600
+ *
489
601
  * @example
602
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
603
+ *
604
+ * // Create a network client.
605
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
606
+ *
490
607
  * const latestHeight = networkClient.getLatestHeight();
491
608
  */
492
609
  async getLatestHeight() {
@@ -500,8 +617,16 @@ class AleoNetworkClient {
500
617
  /**
501
618
  * Returns the latest block hash.
502
619
  *
620
+ * @returns {Promise<string>} The latest block hash.
621
+ *
503
622
  * @example
504
- * const latestHash - newtworkClient.getLatestBlockHash();
623
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
624
+ *
625
+ * // Create a network client.
626
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
627
+ *
628
+ * // Get the latest block hash.
629
+ * const latestHash = networkClient.getLatestBlockHash();
505
630
  */
506
631
  async getLatestBlockHash() {
507
632
  try {
@@ -515,9 +640,14 @@ class AleoNetworkClient {
515
640
  * Returns the source code of a program given a program ID.
516
641
  *
517
642
  * @param {string} programId The program ID of a program deployed to the Aleo Network
518
- * @return {Promise<string>} Source code of the program
643
+ * @returns {Promise<string>} Source code of the program
519
644
  *
520
645
  * @example
646
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
647
+ *
648
+ * // Create a network client.
649
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
650
+ *
521
651
  * const program = networkClient.getProgram("hello_hello.aleo");
522
652
  * const expectedSource = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n"
523
653
  * assert.equal(program, expectedSource);
@@ -534,9 +664,14 @@ class AleoNetworkClient {
534
664
  * Returns a program object from a program ID or program source code.
535
665
  *
536
666
  * @param {string} inputProgram The program ID or program source code of a program deployed to the Aleo Network
537
- * @return {Promise<Program>} Source code of the program
667
+ * @returns {Promise<Program>} Source code of the program
538
668
  *
539
669
  * @example
670
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
671
+ *
672
+ * // Create a network client.
673
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
674
+ *
540
675
  * const programID = "hello_hello.aleo";
541
676
  * const programSource = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n"
542
677
  *
@@ -545,7 +680,7 @@ class AleoNetworkClient {
545
680
  * const programObjectFromSource = await networkClient.getProgramObject(programSource);
546
681
  *
547
682
  * // Both program objects should be equal
548
- * assert.equal(programObjectFromID.to_string(), programObjectFromSource.to_string());
683
+ * assert(programObjectFromID.to_string() === programObjectFromSource.to_string());
549
684
  */
550
685
  async getProgramObject(inputProgram) {
551
686
  try {
@@ -567,12 +702,17 @@ class AleoNetworkClient {
567
702
  * @returns {Promise<ProgramImports>} Object of the form { "program_id": "program_source", .. } containing program id & source code for all program imports
568
703
  *
569
704
  * @example
705
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
706
+ *
570
707
  * const double_test_source = "import multiply_test.aleo;\n\nprogram double_test.aleo;\n\nfunction double_it:\n input r0 as u32.private;\n call multiply_test.aleo/multiply 2u32 r0 into r1;\n output r1 as u32.private;\n"
571
708
  * const double_test = Program.fromString(double_test_source);
572
709
  * const expectedImports = {
573
710
  * "multiply_test.aleo": "program multiply_test.aleo;\n\nfunction multiply:\n input r0 as u32.public;\n input r1 as u32.private;\n mul r0 r1 into r2;\n output r2 as u32.private;\n"
574
711
  * }
575
712
  *
713
+ * // Create a network client.
714
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
715
+ *
576
716
  * // Imports can be fetched using the program ID, source code, or program object
577
717
  * let programImports = await networkClient.getProgramImports("double_test.aleo");
578
718
  * assert.deepStrictEqual(programImports, expectedImports);
@@ -619,8 +759,13 @@ class AleoNetworkClient {
619
759
  * @returns {string[]} - The list of program names that the program imports
620
760
  *
621
761
  * @example
622
- * const programImportsNames = networkClient.getProgramImports("double_test.aleo");
623
- * const expectedImportsNames = ["multiply_test.aleo"];
762
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
763
+ *
764
+ * // Create a network client.
765
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
766
+ *
767
+ * const programImportsNames = networkClient.getProgramImports("wrapped_credits.aleo");
768
+ * const expectedImportsNames = ["credits.aleo"];
624
769
  * assert.deepStrictEqual(programImportsNames, expectedImportsNames);
625
770
  */
626
771
  async getProgramImportNames(inputProgram) {
@@ -636,7 +781,14 @@ class AleoNetworkClient {
636
781
  * Returns the names of the mappings of a program.
637
782
  *
638
783
  * @param {string} programId - The program ID to get the mappings of (e.g. "credits.aleo")
784
+ * @returns {Promise<Array<string>>} - The names of the mappings of the program.
785
+ *
639
786
  * @example
787
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
788
+ *
789
+ * // Create a network client.
790
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
791
+ *
640
792
  * const mappings = networkClient.getProgramMappingNames("credits.aleo");
641
793
  * const expectedMappings = [
642
794
  * "committee",
@@ -662,14 +814,19 @@ class AleoNetworkClient {
662
814
  *
663
815
  * @param {string} programId - The program ID to get the mapping value of (e.g. "credits.aleo")
664
816
  * @param {string} mappingName - The name of the mapping to get the value of (e.g. "account")
665
- * @param {string | Plaintext} key - The key of the mapping to get the value of (e.g. "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px")
666
- * @return {Promise<string>} String representation of the value of the mapping
817
+ * @param {string | Plaintext} key - The key to look up in the mapping (e.g. an address for the "account" mapping)
818
+ * @returns {Promise<string>} String representation of the value of the mapping
667
819
  *
668
820
  * @example
821
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
822
+ *
823
+ * // Create a network client.
824
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
825
+ *
669
826
  * // Get public balance of an account
670
827
  * const mappingValue = networkClient.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
671
828
  * const expectedValue = "0u64";
672
- * assert.equal(mappingValue, expectedValue);
829
+ * assert(mappingValue === expectedValue);
673
830
  */
674
831
  async getProgramMappingValue(programId, mappingName, key) {
675
832
  try {
@@ -681,11 +838,19 @@ class AleoNetworkClient {
681
838
  }
682
839
  }
683
840
  /**
684
- * Returns the value of a mapping as a wasm Plaintext object. Returning an
685
- * object in this format allows it to be converted to a Js type and for its
686
- * internal members to be inspected if it's a struct or array.
841
+ * Returns the value of a mapping as a wasm Plaintext object. Returning an object in this format allows it to be converted to a Js type and for its internal members to be inspected if it's a struct or array.
842
+ *
843
+ * @param {string} programId - The program ID to get the mapping value of (e.g. "credits.aleo")
844
+ * @param {string} mappingName - The name of the mapping to get the value of (e.g. "bonded")
845
+ * @param {string | Plaintext} key - The key to look up in the mapping (e.g. an address for the "bonded" mapping)
846
+ * @returns {Promise<Plaintext>} String representation of the value of the mapping
687
847
  *
688
848
  * @example
849
+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
850
+ *
851
+ * // Create a network client.
852
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
853
+ *
689
854
  * // Get the bond state as an account.
690
855
  * const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
691
856
  *
@@ -702,15 +867,9 @@ class AleoNetworkClient {
702
867
  *
703
868
  * const expectedState = {
704
869
  * validator: "aleo1u6940v5m0fzud859xx2c9tj2gjg6m5qrd28n636e6fdd2akvfcgqs34mfd",
705
- * microcredits: BigInt("9007199254740991")
870
+ * microcredits: BigInt(9007199254740991)
706
871
  * };
707
872
  * assert.equal(unbondedState, expectedState);
708
- *
709
- * @param {string} programId - The program ID to get the mapping value of (e.g. "credits.aleo")
710
- * @param {string} mappingName - The name of the mapping to get the value of (e.g. "account")
711
- * @param {string | Plaintext} key - The key of the mapping to get the value of (e.g. "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px")
712
- *
713
- * @return {Promise<string>} String representation of the value of the mapping
714
873
  */
715
874
  async getProgramMappingPlaintext(programId, mappingName, key) {
716
875
  try {
@@ -725,15 +884,25 @@ class AleoNetworkClient {
725
884
  /**
726
885
  * Returns the public balance of an address from the account mapping in credits.aleo
727
886
  *
728
- * @param {string} address
887
+ * @param {Address | string} address A string or wasm object representing an address.
888
+ * @returns {Promise<number>} The public balance of the address in microcredits.
729
889
  *
730
890
  * @example
731
- * const account = new Account();
732
- * const publicBalance = networkClient.getPublicBalance(account.address());
891
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
892
+ *
893
+ * // Create a network client.
894
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
895
+ *
896
+ * // Get the balance of an account from either an address object or address string.
897
+ * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
898
+ * const publicBalance = await networkClient.getPublicBalance(account.address());
899
+ * const publicBalanceFromString = await networkClient.getPublicBalance(account.address().to_string());
900
+ * assert(publicBalance === publicBalanceFromString);
733
901
  */
734
902
  async getPublicBalance(address) {
735
903
  try {
736
- const balanceStr = await this.getProgramMappingValue('credits.aleo', 'account', address.to_string());
904
+ const addressString = address instanceof Address ? address.to_string() : address;
905
+ const balanceStr = await this.getProgramMappingValue('credits.aleo', 'account', addressString);
737
906
  return balanceStr ? parseInt(balanceStr) : 0;
738
907
  }
739
908
  catch (error) {
@@ -743,7 +912,15 @@ class AleoNetworkClient {
743
912
  /**
744
913
  * Returns the latest state/merkle root of the Aleo blockchain.
745
914
  *
915
+ * @returns {Promise<string>} A string representing the latest state root of the Aleo blockchain.
916
+ *
746
917
  * @example
918
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
919
+ *
920
+ * // Create a network client.
921
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
922
+ *
923
+ * // Get the latest state root.
747
924
  * const stateRoot = networkClient.getStateRoot();
748
925
  */
749
926
  async getStateRoot() {
@@ -757,8 +934,15 @@ class AleoNetworkClient {
757
934
  /**
758
935
  * Returns a transaction by its unique identifier.
759
936
  *
760
- * @param {string} transactionId
937
+ * @param {string} transactionId The transaction ID to fetch.
938
+ * @returns {Promise<TransactionJSON>} A json representation of the transaction.
939
+ *
761
940
  * @example
941
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
942
+ *
943
+ * // Create a network client.
944
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
945
+ *
762
946
  * const transaction = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
763
947
  */
764
948
  async getTransaction(transactionId) {
@@ -772,9 +956,17 @@ class AleoNetworkClient {
772
956
  /**
773
957
  * Returns a confirmed transaction by its unique identifier.
774
958
  *
775
- * @param {string} transactionId
959
+ * @param {string} transactionId The transaction ID to fetch.
960
+ * @returns {Promise<ConfirmedTransactionJSON>} A json object containing the confirmed transaction.
961
+ *
776
962
  * @example
963
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
964
+ *
965
+ * // Create a network client.
966
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
967
+ *
777
968
  * const transaction = networkClient.getConfirmedTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
969
+ * assert.equal(transaction.status, "confirmed");
778
970
  */
779
971
  async getConfirmedTransaction(transactionId) {
780
972
  try {
@@ -788,13 +980,16 @@ class AleoNetworkClient {
788
980
  * Returns a transaction as a wasm object. Getting a transaction of this type will allow the ability for the inputs,
789
981
  * outputs, and records to be searched for and displayed.
790
982
  *
983
+ * @param {string} transactionId - The unique identifier of the transaction to fetch
984
+ * @returns {Promise<Transaction>} A wasm object representation of the transaction.
985
+ *
791
986
  * @example
792
987
  * const transactionObject = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
793
988
  * // Get the transaction inputs as a JS array.
794
- * const transactionOutputs = transactionObject.inputs(true);
989
+ * const transactionInputs = transactionObject.inputs(true);
795
990
  *
796
991
  * // Get the transaction outputs as a JS object.
797
- * const transactionInputs = transactionObject.outputs(true);
992
+ * const transactionOutputs = transactionObject.outputs(true);
798
993
  *
799
994
  * // Get any records generated in transitions in the transaction as a JS object.
800
995
  * const records = transactionObject.records();
@@ -805,10 +1000,6 @@ class AleoNetworkClient {
805
1000
  *
806
1001
  * // Get a JS representation of all inputs, outputs, and transaction metadata.
807
1002
  * const transactionSummary = transactionObject.summary();
808
- *
809
- * @param {string} transactionId
810
- * @example
811
- * const transaction = networkClient.getTransactionObject("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
812
1003
  */
813
1004
  async getTransactionObject(transactionId) {
814
1005
  try {
@@ -822,8 +1013,15 @@ class AleoNetworkClient {
822
1013
  /**
823
1014
  * Returns the transactions present at the specified block height.
824
1015
  *
825
- * @param {number} blockHeight
1016
+ * @param {number} blockHeight The block height to fetch the confirmed transactions at.
1017
+ * @returns {Promise<Array<ConfirmedTransactionJSON>>} An array of confirmed transactions (in JSON format) for the block height.
1018
+ *
826
1019
  * @example
1020
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
1021
+ *
1022
+ * // Create a network client.
1023
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1024
+ *
827
1025
  * const transactions = networkClient.getTransactions(654);
828
1026
  */
829
1027
  async getTransactions(blockHeight) {
@@ -837,9 +1035,16 @@ class AleoNetworkClient {
837
1035
  /**
838
1036
  * Returns the confirmed transactions present in the block with the specified block hash.
839
1037
  *
840
- * @param {string} blockHash
1038
+ * @param {string} blockHash The block hash to fetch the confirmed transactions at.
1039
+ * @returns {Promise<Array<ConfirmedTransactionJSON>>} An array of confirmed transactions (in JSON format) for the block hash.
1040
+ *
841
1041
  * @example
842
- * const transactions = networkClient.getTransactionsByHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
1042
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
1043
+ *
1044
+ * // Create a network client.
1045
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1046
+ *
1047
+ * const transactions = networkClient.getTransactionsByBlockHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
843
1048
  */
844
1049
  async getTransactionsByBlockHash(blockHash) {
845
1050
  try {
@@ -854,7 +1059,15 @@ class AleoNetworkClient {
854
1059
  /**
855
1060
  * Returns the transactions in the memory pool. This method requires access to a validator's REST API.
856
1061
  *
1062
+ * @returns {Promise<Array<TransactionJSON>>} An array of transactions (in JSON format) currently in the mempool.
1063
+ *
857
1064
  * @example
1065
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js";
1066
+ *
1067
+ * // Create a network client.
1068
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1069
+ *
1070
+ * // Get the current transactions in the mempool.
858
1071
  * const transactions = networkClient.getTransactionsInMempool();
859
1072
  */
860
1073
  async getTransactionsInMempool() {
@@ -867,7 +1080,8 @@ class AleoNetworkClient {
867
1080
  }
868
1081
  /**
869
1082
  * Returns the transition ID of the transition corresponding to the ID of the input or output.
870
- * @param {string} inputOrOutputID - ID of the input or output.
1083
+ * @param {string} inputOrOutputID - The unique identifier of the input or output to find the transition ID for
1084
+ * @returns {Promise<string>} - The transition ID of the input or output ID.
871
1085
  *
872
1086
  * @example
873
1087
  * const transitionId = networkClient.getTransitionId("2429232855236830926144356377868449890830704336664550203176918782554219952323field");
@@ -883,8 +1097,8 @@ class AleoNetworkClient {
883
1097
  /**
884
1098
  * Submit an execute or deployment transaction to the Aleo network.
885
1099
  *
886
- * @param {Transaction | string} transaction - The transaction to submit to the network
887
- * @returns {string} - The transaction id of the submitted transaction or the resulting error
1100
+ * @param {Transaction | string} transaction - The transaction to submit, either as a Transaction object or string representation
1101
+ * @returns {Promise<string>} - The transaction id of the submitted transaction or the resulting error
888
1102
  */
889
1103
  async submitTransaction(transaction) {
890
1104
  const transaction_string = transaction instanceof Transaction ? transaction.toString() : transaction;
@@ -910,7 +1124,8 @@ class AleoNetworkClient {
910
1124
  /**
911
1125
  * Submit a solution to the Aleo network.
912
1126
  *
913
- * @param {string} solution The string representation of the solution desired to be submitted to the network.
1127
+ * @param {string} solution - The string representation of the solution to submit
1128
+ * @returns {Promise<string>} The solution id of the submitted solution or the resulting error.
914
1129
  */
915
1130
  async submitSolution(solution) {
916
1131
  try {
@@ -933,9 +1148,31 @@ class AleoNetworkClient {
933
1148
  }
934
1149
  }
935
1150
  /**
936
- * Await a transaction to be confirmed on the Aleo network.
1151
+ * Await a submitted transaction to be confirmed or rejected on the Aleo network.
1152
+ *
1153
+ * @param {string} transactionId - The transaction ID to wait for confirmation
1154
+ * @param {number} checkInterval - The interval in milliseconds to check for confirmation (default: 2000)
1155
+ * @param {number} timeout - The maximum time in milliseconds to wait for confirmation (default: 45000)
1156
+ * @returns {Promise<Transaction>} The confirmed transaction object that returns if the transaction is confirmed.
1157
+ *
1158
+ * @example
1159
+ * import { AleoNetworkClient, Account, ProgramManager } from "@provablehq/sdk/mainnet.js";
1160
+ *
1161
+ * // Create a network client and program manager.
1162
+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1163
+ * const programManager = new ProgramManager(networkClient);
937
1164
  *
938
- * @param {string} solution The string representation of the solution desired to be submitted to the network.
1165
+ * // Set the account for the program manager.
1166
+ * programManager.setAccount(Account.fromCiphertext(process.env.ciphertext, process.env.password));
1167
+ *
1168
+ * // Build a transfer transaction.
1169
+ * const tx = await programManager.buildTransferPublicTransaction(100, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0);
1170
+ *
1171
+ * // Submit the transaction to the network.
1172
+ * const transactionId = await networkClient.submitTransaction(tx);
1173
+ *
1174
+ * // Wait for the transaction to be confirmed.
1175
+ * const transaction = await networkClient.waitForTransactionConfirmation(transactionId);
939
1176
  */
940
1177
  async waitForTransactionConfirmation(transactionId, checkInterval = 2000, // Poll every 2 seconds
941
1178
  timeout = 45000 // Timeout after 45 seconds
@@ -1473,11 +1710,20 @@ class ProgramManager {
1473
1710
  * @param { RecordProvider | undefined } recordProvider A record provider that implements {@link RecordProvider} interface
1474
1711
  */
1475
1712
  constructor(host, keyProvider, recordProvider) {
1476
- this.host = host ? host : 'https://api.explorer.provable.com/v1';
1713
+ this.host = host ? host : "https://api.explorer.provable.com/v1";
1477
1714
  this.networkClient = new AleoNetworkClient(this.host);
1478
1715
  this.keyProvider = keyProvider ? keyProvider : new AleoKeyProvider();
1479
1716
  this.recordProvider = recordProvider;
1480
1717
  }
1718
+ /**
1719
+ * Check if the fee is sufficient to pay for the transaction
1720
+ */
1721
+ async checkFee(address, feeAmount) {
1722
+ const balance = BigInt(await this.networkClient.getPublicBalance(address));
1723
+ if (feeAmount > balance) {
1724
+ throw Error(`The desired execution requires a fee of ${feeAmount} microcredits, but the account paying the fee has ${balance} microcredits available.`);
1725
+ }
1726
+ }
1481
1727
  /**
1482
1728
  * Set the account to use for transaction submission to the Aleo network
1483
1729
  *
@@ -1515,34 +1761,51 @@ class ProgramManager {
1515
1761
  * Builds a deployment transaction for submission to the Aleo network.
1516
1762
  *
1517
1763
  * @param {string} program Program source code
1518
- * @param {number} fee Fee to pay for the transaction
1764
+ * @param {number} priorityFee The optional priority fee to be paid for that transaction.
1519
1765
  * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
1520
- * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for searching for a record to use
1521
- * pay the deployment fee
1766
+ * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for searching for a record to use pay the deployment fee
1522
1767
  * @param {string | RecordPlaintext | undefined} feeRecord Optional Fee record to use for the transaction
1523
1768
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transaction
1524
1769
  * @returns {string} The transaction id of the deployed program or a failure message from the network
1525
1770
  *
1526
1771
  * @example
1772
+ * /// Import the mainnet version of the sdk.
1773
+ * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
1774
+ *
1527
1775
  * // Create a new NetworkClient, KeyProvider, and RecordProvider
1528
- * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
1529
1776
  * const keyProvider = new AleoKeyProvider();
1530
1777
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
1778
+ * keyProvider.useCache = true;
1531
1779
  *
1532
1780
  * // Initialize a program manager with the key provider to automatically fetch keys for deployments
1533
1781
  * const program = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
1534
1782
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
1783
+ * programManager.setAccount(Account);
1535
1784
  *
1536
1785
  * // Define a fee in credits
1537
- * const fee = 1.2;
1786
+ * const priorityFee = 0.0;
1538
1787
  *
1539
1788
  * // Create the deployment transaction.
1540
1789
  * const tx = await programManager.buildDeploymentTransaction(program, fee, false);
1541
- */
1542
- async buildDeploymentTransaction(program, fee, privateFee, recordSearchParams, feeRecord, privateKey) {
1790
+ * await programManager.networkClient.submitTransaction(tx);
1791
+ *
1792
+ * // Verify the transaction was successful
1793
+ * setTimeout(async () => {
1794
+ * const transaction = await programManager.networkClient.getTransaction(tx.id());
1795
+ * assert(transaction.id() === tx.id());
1796
+ * }, 20000);
1797
+ */
1798
+ async buildDeploymentTransaction(program, priorityFee, privateFee, recordSearchParams, feeRecord, privateKey) {
1799
+ // Ensure the program is valid.
1800
+ let programObject;
1801
+ try {
1802
+ programObject = Program.fromString(program);
1803
+ }
1804
+ catch (e) {
1805
+ logAndThrow(`Error parsing program: '${e.message}'. Please ensure the program is valid.`);
1806
+ }
1543
1807
  // Ensure the program is valid and does not exist on the network
1544
1808
  try {
1545
- const programObject = Program.fromString(program);
1546
1809
  let programSource;
1547
1810
  try {
1548
1811
  programSource = await this.networkClient.getProgram(programObject.id());
@@ -1551,8 +1814,8 @@ class ProgramManager {
1551
1814
  // Program does not exist on the network, deployment can proceed
1552
1815
  console.log(`Program ${programObject.id()} does not exist on the network, deploying...`);
1553
1816
  }
1554
- if (typeof programSource == "string") {
1555
- throw (`Program ${programObject.id()} already exists on the network, please rename your program`);
1817
+ if (typeof programSource === "string") {
1818
+ throw Error(`Program ${programObject.id()} already exists on the network, please rename your program`);
1556
1819
  }
1557
1820
  }
1558
1821
  catch (e) {
@@ -1560,15 +1823,18 @@ class ProgramManager {
1560
1823
  }
1561
1824
  // Get the private key from the account if it is not provided in the parameters
1562
1825
  let deploymentPrivateKey = privateKey;
1563
- if (typeof privateKey === "undefined" && typeof this.account !== "undefined") {
1826
+ if (typeof privateKey === "undefined" &&
1827
+ typeof this.account !== "undefined") {
1564
1828
  deploymentPrivateKey = this.account.privateKey();
1565
1829
  }
1566
1830
  if (typeof deploymentPrivateKey === "undefined") {
1567
- throw ("No private key provided and no private key set in the ProgramManager");
1831
+ throw "No private key provided and no private key set in the ProgramManager";
1568
1832
  }
1569
1833
  // Get the fee record from the account if it is not provided in the parameters
1570
1834
  try {
1571
- feeRecord = privateFee ? await this.getCreditsRecord(fee, [], feeRecord, recordSearchParams) : undefined;
1835
+ feeRecord = privateFee
1836
+ ? (await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams))
1837
+ : undefined;
1572
1838
  }
1573
1839
  catch (e) {
1574
1840
  logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
@@ -1576,7 +1842,9 @@ class ProgramManager {
1576
1842
  // Get the proving and verifying keys from the key provider
1577
1843
  let feeKeys;
1578
1844
  try {
1579
- feeKeys = privateFee ? await this.keyProvider.feePrivateKeys() : await this.keyProvider.feePublicKeys();
1845
+ feeKeys = privateFee
1846
+ ? await this.keyProvider.feePrivateKeys()
1847
+ : await this.keyProvider.feePublicKeys();
1580
1848
  }
1581
1849
  catch (e) {
1582
1850
  logAndThrow(`Error finding fee keys. Key finder response: '${e.message}'. Please ensure your key provider is configured correctly.`);
@@ -1590,42 +1858,59 @@ class ProgramManager {
1590
1858
  catch (e) {
1591
1859
  logAndThrow(`Error finding program imports. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network and the program is deployed to the network.`);
1592
1860
  }
1593
- // Build a deployment transaction and submit it to the network
1594
- return await ProgramManager$1.buildDeploymentTransaction(deploymentPrivateKey, program, fee, feeRecord, this.host, imports, feeProvingKey, feeVerifyingKey);
1861
+ // Build a deployment transaction
1862
+ return await ProgramManager$1.buildDeploymentTransaction(deploymentPrivateKey, program, priorityFee, feeRecord, this.host, imports, feeProvingKey, feeVerifyingKey);
1595
1863
  }
1596
1864
  /**
1597
1865
  * Deploy an Aleo program to the Aleo network
1598
1866
  *
1599
1867
  * @param {string} program Program source code
1600
- * @param {number} fee Fee to pay for the transaction
1868
+ * @param {number} priorityFee The optional fee to be paid for the transaction
1601
1869
  * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
1602
- * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for searching for a record to use
1603
- * pay the deployment fee
1870
+ * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for searching for a record to used pay the deployment fee
1604
1871
  * @param {string | RecordPlaintext | undefined} feeRecord Optional Fee record to use for the transaction
1605
1872
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transaction
1606
1873
  * @returns {string} The transaction id of the deployed program or a failure message from the network
1607
1874
  *
1608
1875
  * @example
1876
+ * /// Import the mainnet version of the sdk.
1877
+ * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
1878
+ *
1609
1879
  * // Create a new NetworkClient, KeyProvider, and RecordProvider
1610
- * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
1611
1880
  * const keyProvider = new AleoKeyProvider();
1612
1881
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
1882
+ * keyProvider.useCache = true;
1613
1883
  *
1614
1884
  * // Initialize a program manager with the key provider to automatically fetch keys for deployments
1615
1885
  * const program = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
1616
1886
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
1617
1887
  *
1618
1888
  * // Define a fee in credits
1619
- * const fee = 1.2;
1889
+ * const priorityFee = 0.0;
1620
1890
  *
1621
1891
  * // Deploy the program
1622
1892
  * const tx_id = await programManager.deploy(program, fee, false);
1623
1893
  *
1624
1894
  * // Verify the transaction was successful
1625
- * const transaction = await programManager.networkClient.getTransaction(tx_id);
1895
+ * setTimeout(async () => {
1896
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
1897
+ * assert(transaction.id() === tx_id);
1898
+ * }, 20000);
1626
1899
  */
1627
- async deploy(program, fee, privateFee, recordSearchParams, feeRecord, privateKey) {
1628
- const tx = await this.buildDeploymentTransaction(program, fee, privateFee, recordSearchParams, feeRecord, privateKey);
1900
+ async deploy(program, priorityFee, privateFee, recordSearchParams, feeRecord, privateKey) {
1901
+ const tx = (await this.buildDeploymentTransaction(program, priorityFee, privateFee, recordSearchParams, feeRecord, privateKey));
1902
+ let feeAddress;
1903
+ if (typeof privateKey !== "undefined") {
1904
+ feeAddress = Address.from_private_key(privateKey);
1905
+ }
1906
+ else if (this.account !== undefined) {
1907
+ feeAddress = this.account?.address();
1908
+ }
1909
+ else {
1910
+ throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
1911
+ }
1912
+ // Check if the account has sufficient credits to pay for the transaction
1913
+ await this.checkFee(feeAddress.to_string(), tx.feeAmount());
1629
1914
  return await this.networkClient.submitTransaction(tx);
1630
1915
  }
1631
1916
  /**
@@ -1635,29 +1920,39 @@ class ProgramManager {
1635
1920
  * @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error.
1636
1921
  *
1637
1922
  * @example
1923
+ * /// Import the mainnet version of the sdk.
1924
+ * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
1925
+ *
1638
1926
  * // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers
1639
- * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
1640
1927
  * const keyProvider = new AleoKeyProvider();
1641
- * keyProvider.useCache = true;
1642
1928
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
1929
+ * keyProvider.useCache = true;
1643
1930
  *
1644
1931
  * // Initialize a program manager with the key provider to automatically fetch keys for executions
1645
1932
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
1646
1933
  *
1647
1934
  * // Build and execute the transaction
1648
- * const transaction = await programManager.buildExecutionTransaction({
1935
+ * const tx = await programManager.buildExecutionTransaction({
1649
1936
  * programName: "hello_hello.aleo",
1650
1937
  * functionName: "hello_hello",
1651
- * fee: 0.020,
1938
+ * priorityFee: 0.0,
1652
1939
  * privateFee: false,
1653
1940
  * inputs: ["5u32", "5u32"],
1654
1941
  * keySearchParams: { "cacheKey": "hello_hello:hello" }
1655
1942
  * });
1656
- * const result = await programManager.networkClient.submitTransaction(transaction);
1943
+ *
1944
+ * // Submit the transaction to the network
1945
+ * await programManager.networkClient.submitTransaction(tx.toString());
1946
+ *
1947
+ * // Verify the transaction was successful
1948
+ * setTimeout(async () => {
1949
+ * const transaction = await programManager.networkClient.getTransaction(tx.id());
1950
+ * assert(transaction.id() === tx.id());
1951
+ * }, 10000);
1657
1952
  */
1658
1953
  async buildExecutionTransaction(options) {
1659
1954
  // Destructure the options object to access the parameters
1660
- const { programName, functionName, fee, privateFee, inputs, recordSearchParams, keySearchParams, privateKey, offlineQuery } = options;
1955
+ const { programName, functionName, priorityFee, privateFee, inputs, recordSearchParams, keySearchParams, privateKey, offlineQuery, } = options;
1661
1956
  let feeRecord = options.feeRecord;
1662
1957
  let provingKey = options.provingKey;
1663
1958
  let verifyingKey = options.verifyingKey;
@@ -1677,15 +1972,18 @@ class ProgramManager {
1677
1972
  }
1678
1973
  // Get the private key from the account if it is not provided in the parameters
1679
1974
  let executionPrivateKey = privateKey;
1680
- if (typeof privateKey === "undefined" && typeof this.account !== "undefined") {
1975
+ if (typeof privateKey === "undefined" &&
1976
+ typeof this.account !== "undefined") {
1681
1977
  executionPrivateKey = this.account.privateKey();
1682
1978
  }
1683
1979
  if (typeof executionPrivateKey === "undefined") {
1684
- throw ("No private key provided and no private key set in the ProgramManager");
1980
+ throw "No private key provided and no private key set in the ProgramManager";
1685
1981
  }
1686
1982
  // Get the fee record from the account if it is not provided in the parameters
1687
1983
  try {
1688
- feeRecord = privateFee ? await this.getCreditsRecord(fee, [], feeRecord, recordSearchParams) : undefined;
1984
+ feeRecord = privateFee
1985
+ ? (await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams))
1986
+ : undefined;
1689
1987
  }
1690
1988
  catch (e) {
1691
1989
  logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
@@ -1693,7 +1991,9 @@ class ProgramManager {
1693
1991
  // Get the fee proving and verifying keys from the key provider
1694
1992
  let feeKeys;
1695
1993
  try {
1696
- feeKeys = privateFee ? await this.keyProvider.feePrivateKeys() : await this.keyProvider.feePublicKeys();
1994
+ feeKeys = privateFee
1995
+ ? await this.keyProvider.feePrivateKeys()
1996
+ : await this.keyProvider.feePublicKeys();
1697
1997
  }
1698
1998
  catch (e) {
1699
1999
  logAndThrow(`Error finding fee keys. Key finder response: '${e.message}'. Please ensure your key provider is configured correctly.`);
@@ -1702,7 +2002,7 @@ class ProgramManager {
1702
2002
  // If the function proving and verifying keys are not provided, attempt to find them using the key provider
1703
2003
  if (!provingKey || !verifyingKey) {
1704
2004
  try {
1705
- [provingKey, verifyingKey] = await this.keyProvider.functionKeys(keySearchParams);
2005
+ [provingKey, verifyingKey] = (await this.keyProvider.functionKeys(keySearchParams));
1706
2006
  }
1707
2007
  catch (e) {
1708
2008
  console.log(`Function keys not found. Key finder response: '${e}'. The function keys will be synthesized`);
@@ -1712,44 +2012,63 @@ class ProgramManager {
1712
2012
  const numberOfImports = Program.fromString(program).getImports().length;
1713
2013
  if (numberOfImports > 0 && !imports) {
1714
2014
  try {
1715
- imports = await this.networkClient.getProgramImports(programName);
2015
+ imports = (await this.networkClient.getProgramImports(programName));
1716
2016
  }
1717
2017
  catch (e) {
1718
2018
  logAndThrow(`Error finding program imports. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network and the program is deployed to the network.`);
1719
2019
  }
1720
2020
  }
1721
- // Build an execution transaction and submit it to the network
1722
- return await ProgramManager$1.buildExecutionTransaction(executionPrivateKey, program, functionName, inputs, fee, feeRecord, this.host, imports, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
2021
+ // Build an execution transaction
2022
+ return await ProgramManager$1.buildExecutionTransaction(executionPrivateKey, program, functionName, inputs, priorityFee, feeRecord, this.host, imports, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
1723
2023
  }
1724
2024
  /**
1725
2025
  * Builds an execution transaction for submission to the Aleo network.
1726
2026
  *
1727
2027
  * @param {ExecuteOptions} options - The options for the execution transaction.
1728
- * @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error.
2028
+ * @returns {Promise<string>} - The transaction id
1729
2029
  *
1730
2030
  * @example
2031
+ * /// Import the mainnet version of the sdk.
2032
+ * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
2033
+ *
1731
2034
  * // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers
1732
- * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
1733
2035
  * const keyProvider = new AleoKeyProvider();
1734
- * keyProvider.useCache = true;
1735
2036
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
2037
+ * keyProvider.useCache = true;
1736
2038
  *
1737
2039
  * // Initialize a program manager with the key provider to automatically fetch keys for executions
1738
2040
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
1739
2041
  *
1740
2042
  * // Build and execute the transaction
1741
- * const transaction = await programManager.execute({
2043
+ * const tx_id = await programManager.execute({
1742
2044
  * programName: "hello_hello.aleo",
1743
2045
  * functionName: "hello_hello",
1744
- * fee: 0.020,
2046
+ * priorityFee: 0.0,
1745
2047
  * privateFee: false,
1746
2048
  * inputs: ["5u32", "5u32"],
1747
2049
  * keySearchParams: { "cacheKey": "hello_hello:hello" }
1748
2050
  * });
1749
- * const result = await programManager.networkClient.submitTransaction(transaction);
2051
+ *
2052
+ * // Verify the transaction was successful
2053
+ * setTimeout(async () => {
2054
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
2055
+ * assert(transaction.id() === tx_id);
2056
+ * }, 10000);
1750
2057
  */
1751
2058
  async execute(options) {
1752
2059
  const tx = await this.buildExecutionTransaction(options);
2060
+ let feeAddress;
2061
+ if (typeof options.privateKey !== "undefined") {
2062
+ feeAddress = Address.from_private_key(options.privateKey);
2063
+ }
2064
+ else if (this.account !== undefined) {
2065
+ feeAddress = this.account?.address();
2066
+ }
2067
+ else {
2068
+ throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
2069
+ }
2070
+ // Check if the account has sufficient credits to pay for the transaction
2071
+ await this.checkFee(feeAddress.to_string(), tx.feeAmount());
1753
2072
  return await this.networkClient.submitTransaction(tx);
1754
2073
  }
1755
2074
  /**
@@ -1758,23 +2077,22 @@ class ProgramManager {
1758
2077
  * @param {string} program Program source code containing the function to be executed
1759
2078
  * @param {string} function_name Function name to execute
1760
2079
  * @param {string[]} inputs Inputs to the function
1761
- * @param {number} proveExecution Whether to prove the execution of the function and return an execution transcript
1762
- * that contains the proof.
2080
+ * @param {number} proveExecution Whether to prove the execution of the function and return an execution transcript that contains the proof.
1763
2081
  * @param {string[] | undefined} imports Optional imports to the program
1764
- * @param {KeySearchParams | undefined} keySearchParams Optional parameters for finding the matching proving &
1765
- * verifying keys for the function
2082
+ * @param {KeySearchParams | undefined} keySearchParams Optional parameters for finding the matching proving & verifying keys for the function
1766
2083
  * @param {ProvingKey | undefined} provingKey Optional proving key to use for the transaction
1767
2084
  * @param {VerifyingKey | undefined} verifyingKey Optional verifying key to use for the transaction
1768
2085
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transaction
1769
2086
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
1770
- * @returns {Promise<string>}
2087
+ * @returns {Promise<ExecutionResponse>} The execution response containing the outputs of the function and the proof if the program is proved.
1771
2088
  *
1772
2089
  * @example
1773
- * import { Account, Program } from '@provablehq/sdk';
2090
+ * /// Import the mainnet version of the sdk used to build executions.
2091
+ * import { Account, ProgramManager } from "@provablehq/sdk/mainnet.js";
1774
2092
  *
1775
2093
  * /// Create the source for the "helloworld" program
1776
2094
  * const program = "program helloworld.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
1777
- * const programManager = new ProgramManager();
2095
+ * const programManager = new ProgramManager(undefined, undefined, undefined);
1778
2096
  *
1779
2097
  * /// Create a temporary account for the execution of the program
1780
2098
  * const account = new Account();
@@ -1788,16 +2106,17 @@ class ProgramManager {
1788
2106
  async run(program, function_name, inputs, proveExecution, imports, keySearchParams, provingKey, verifyingKey, privateKey, offlineQuery) {
1789
2107
  // Get the private key from the account if it is not provided in the parameters
1790
2108
  let executionPrivateKey = privateKey;
1791
- if (typeof privateKey === "undefined" && typeof this.account !== "undefined") {
2109
+ if (typeof privateKey === "undefined" &&
2110
+ typeof this.account !== "undefined") {
1792
2111
  executionPrivateKey = this.account.privateKey();
1793
2112
  }
1794
2113
  if (typeof executionPrivateKey === "undefined") {
1795
- throw ("No private key provided and no private key set in the ProgramManager");
2114
+ throw "No private key provided and no private key set in the ProgramManager";
1796
2115
  }
1797
2116
  // If the function proving and verifying keys are not provided, attempt to find them using the key provider
1798
2117
  if (!provingKey || !verifyingKey) {
1799
2118
  try {
1800
- [provingKey, verifyingKey] = await this.keyProvider.functionKeys(keySearchParams);
2119
+ [provingKey, verifyingKey] = (await this.keyProvider.functionKeys(keySearchParams));
1801
2120
  }
1802
2121
  catch (e) {
1803
2122
  console.log(`Function keys not found. Key finder response: '${e}'. The function keys will be synthesized`);
@@ -1814,29 +2133,57 @@ class ProgramManager {
1814
2133
  *
1815
2134
  * @param {RecordPlaintext | string} recordOne First credits record to join
1816
2135
  * @param {RecordPlaintext | string} recordTwo Second credits record to join
1817
- * @param {number} fee Fee in credits pay for the join transaction
2136
+ * @param {number} priorityFee The optional priority fee to be paid for the transaction
1818
2137
  * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
1819
- * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the fee record to use
1820
- * to pay the fee for the join transaction
2138
+ * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the fee record to use to pay the fee for the join transaction
1821
2139
  * @param {RecordPlaintext | string | undefined} feeRecord Fee record to use for the join transaction
1822
2140
  * @param {PrivateKey | undefined} privateKey Private key to use for the join transaction
1823
2141
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
1824
- * @returns {Promise<string>}
2142
+ * @returns {Promise<string>} The transaction id
2143
+ *
2144
+ * @example
2145
+ * /// Import the mainnet version of the sdk.
2146
+ * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
2147
+ *
2148
+ * // Create a new NetworkClient, KeyProvider, and RecordProvider
2149
+ * const keyProvider = new AleoKeyProvider();
2150
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
2151
+ * keyProvider.useCache = true;
2152
+ *
2153
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions
2154
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
2155
+ * const record_1 = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
2156
+ * const record_2 = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 1540945439182663264862696551825005342995406165131907382295858612069623286213group.public}"
2157
+ * const tx_id = await programManager.join(record_1, record_2, 0.05, false);
2158
+ *
2159
+ * // Verify the transaction was successful
2160
+ * setTimeout(async () => {
2161
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
2162
+ * assert(transaction.id() === tx_id);
2163
+ * }, 10000);
1825
2164
  */
1826
- async join(recordOne, recordTwo, fee, privateFee, recordSearchParams, feeRecord, privateKey, offlineQuery) {
1827
- // Get the private key from the account if it is not provided in the parameters
2165
+ async join(recordOne, recordTwo, priorityFee, privateFee, recordSearchParams, feeRecord, privateKey, offlineQuery) {
2166
+ // Get the private key from the account if it is not provided in the parameters and assign the fee address
1828
2167
  let executionPrivateKey = privateKey;
1829
- if (typeof privateKey === "undefined" && typeof this.account !== "undefined") {
2168
+ let feeAddress;
2169
+ if (typeof privateKey === "undefined" &&
2170
+ typeof this.account !== "undefined") {
1830
2171
  executionPrivateKey = this.account.privateKey();
2172
+ feeAddress = this.account?.address();
1831
2173
  }
1832
- if (typeof executionPrivateKey === "undefined") {
1833
- throw ("No private key provided and no private key set in the ProgramManager");
2174
+ else if (typeof executionPrivateKey === "undefined") {
2175
+ throw "No private key provided and no private key set in the ProgramManager";
2176
+ }
2177
+ else {
2178
+ feeAddress = Address.from_private_key(executionPrivateKey);
1834
2179
  }
1835
2180
  // Get the proving and verifying keys from the key provider
1836
2181
  let feeKeys;
1837
2182
  let joinKeys;
1838
2183
  try {
1839
- feeKeys = privateFee ? await this.keyProvider.feePrivateKeys() : await this.keyProvider.feePublicKeys();
2184
+ feeKeys = privateFee
2185
+ ? await this.keyProvider.feePrivateKeys()
2186
+ : await this.keyProvider.feePublicKeys();
1840
2187
  joinKeys = await this.keyProvider.joinKeys();
1841
2188
  }
1842
2189
  catch (e) {
@@ -1846,21 +2193,31 @@ class ProgramManager {
1846
2193
  const [joinProvingKey, joinVerifyingKey] = joinKeys;
1847
2194
  // Get the fee record from the account if it is not provided in the parameters
1848
2195
  try {
1849
- feeRecord = privateFee ? await this.getCreditsRecord(fee, [], feeRecord, recordSearchParams) : undefined;
2196
+ feeRecord = privateFee
2197
+ ? (await this.getCreditsRecord(priorityFee, [], feeRecord, recordSearchParams))
2198
+ : undefined;
1850
2199
  }
1851
2200
  catch (e) {
1852
2201
  logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
1853
2202
  }
1854
2203
  // Validate the records provided are valid plaintext records
1855
2204
  try {
1856
- recordOne = recordOne instanceof RecordPlaintext ? recordOne : RecordPlaintext.fromString(recordOne);
1857
- recordTwo = recordTwo instanceof RecordPlaintext ? recordTwo : RecordPlaintext.fromString(recordTwo);
2205
+ recordOne =
2206
+ recordOne instanceof RecordPlaintext
2207
+ ? recordOne
2208
+ : RecordPlaintext.fromString(recordOne);
2209
+ recordTwo =
2210
+ recordTwo instanceof RecordPlaintext
2211
+ ? recordTwo
2212
+ : RecordPlaintext.fromString(recordTwo);
1858
2213
  }
1859
2214
  catch (e) {
1860
- logAndThrow('Records provided are not valid. Please ensure they are valid plaintext records.');
2215
+ logAndThrow("Records provided are not valid. Please ensure they are valid plaintext records.");
1861
2216
  }
1862
2217
  // Build an execution transaction and submit it to the network
1863
- const tx = await ProgramManager$1.buildJoinTransaction(executionPrivateKey, recordOne, recordTwo, fee, feeRecord, this.host, joinProvingKey, joinVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
2218
+ const tx = await ProgramManager$1.buildJoinTransaction(executionPrivateKey, recordOne, recordTwo, priorityFee, feeRecord, this.host, joinProvingKey, joinVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
2219
+ // Check if the account has sufficient credits to pay for the transaction
2220
+ await this.checkFee(feeAddress.to_string(), tx.feeAmount());
1864
2221
  return await this.networkClient.submitTransaction(tx);
1865
2222
  }
1866
2223
  /**
@@ -1870,29 +2227,37 @@ class ProgramManager {
1870
2227
  * @param {RecordPlaintext | string} amountRecord Amount record to use for the split transaction
1871
2228
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the split transaction
1872
2229
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
1873
- * @returns {Promise<string>}
2230
+ * @returns {Promise<string>} The transaction id
1874
2231
  *
1875
2232
  * @example
2233
+ * /// Import the mainnet version of the sdk.
2234
+ * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
2235
+ *
1876
2236
  * // Create a new NetworkClient, KeyProvider, and RecordProvider
1877
- * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
1878
2237
  * const keyProvider = new AleoKeyProvider();
1879
2238
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
2239
+ * keyProvider.useCache = true;
1880
2240
  *
1881
2241
  * // Initialize a program manager with the key provider to automatically fetch keys for executions
1882
- * const programName = "hello_hello.aleo";
1883
2242
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
1884
2243
  * const record = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
1885
2244
  * const tx_id = await programManager.split(25000000, record);
1886
- * const transaction = await programManager.networkClient.getTransaction(tx_id);
2245
+ *
2246
+ * // Verify the transaction was successful
2247
+ * setTimeout(async () => {
2248
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
2249
+ * assert(transaction.id() === tx_id);
2250
+ * }, 10000);
1887
2251
  */
1888
2252
  async split(splitAmount, amountRecord, privateKey, offlineQuery) {
1889
2253
  // Get the private key from the account if it is not provided in the parameters
1890
2254
  let executionPrivateKey = privateKey;
1891
- if (typeof executionPrivateKey === "undefined" && typeof this.account !== "undefined") {
2255
+ if (typeof privateKey === "undefined" &&
2256
+ typeof this.account !== "undefined") {
1892
2257
  executionPrivateKey = this.account.privateKey();
1893
2258
  }
1894
2259
  if (typeof executionPrivateKey === "undefined") {
1895
- throw ("No private key provided and no private key set in the ProgramManager");
2260
+ throw "No private key provided and no private key set in the ProgramManager";
1896
2261
  }
1897
2262
  // Get the split keys from the key provider
1898
2263
  let splitKeys;
@@ -1905,7 +2270,10 @@ class ProgramManager {
1905
2270
  const [splitProvingKey, splitVerifyingKey] = splitKeys;
1906
2271
  // Validate the record to be split
1907
2272
  try {
1908
- amountRecord = amountRecord instanceof RecordPlaintext ? amountRecord : RecordPlaintext.fromString(amountRecord);
2273
+ amountRecord =
2274
+ amountRecord instanceof RecordPlaintext
2275
+ ? amountRecord
2276
+ : RecordPlaintext.fromString(amountRecord);
1909
2277
  }
1910
2278
  catch (e) {
1911
2279
  logAndThrow("Record provided is not valid. Please ensure it is a valid plaintext record.");
@@ -1940,7 +2308,10 @@ class ProgramManager {
1940
2308
  try {
1941
2309
  imports = await this.networkClient.getProgramImports(program);
1942
2310
  const keyPair = await ProgramManager$1.synthesizeKeyPair(executionPrivateKey, program, function_id, inputs, imports);
1943
- return [keyPair.provingKey(), keyPair.verifyingKey()];
2311
+ return [
2312
+ keyPair.provingKey(),
2313
+ keyPair.verifyingKey(),
2314
+ ];
1944
2315
  }
1945
2316
  catch (e) {
1946
2317
  logAndThrow(`Could not synthesize keys - error ${e.message}. Please ensure the program is valid and the inputs are correct.`);
@@ -1952,46 +2323,55 @@ class ProgramManager {
1952
2323
  * @param {number} amount The amount of credits to transfer
1953
2324
  * @param {string} recipient The recipient of the transfer
1954
2325
  * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate'
1955
- * @param {number} fee The fee to pay for the transfer
2326
+ * @param {number} priorityFee The optional priority fee to be paid for the transaction
1956
2327
  * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
1957
- * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee
1958
- * records for the transfer transaction
2328
+ * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee records for the transfer transaction
1959
2329
  * @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer
1960
2330
  * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
1961
2331
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
1962
2332
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
1963
- * @returns {Promise<string>} The transaction id of the transfer transaction
2333
+ * @returns {Promise<Transaction>} The transaction object
1964
2334
  *
1965
2335
  * @example
2336
+ * /// Import the mainnet version of the sdk.
2337
+ * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
2338
+ *
1966
2339
  * // Create a new NetworkClient, KeyProvider, and RecordProvider
1967
- * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
1968
2340
  * const keyProvider = new AleoKeyProvider();
1969
2341
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
2342
+ * keyProvider.useCache = true;
1970
2343
  *
1971
2344
  * // Initialize a program manager with the key provider to automatically fetch keys for executions
1972
- * const programName = "hello_hello.aleo";
1973
2345
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
1974
- * await programManager.initialize();
1975
- * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "private", 0.2)
1976
- * const transaction = await programManager.networkClient.getTransaction(tx_id);
2346
+ * const tx = await programManager.buildTransferTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "public", 0.2, false);
2347
+ * await programManager.networkClient.submitTransaction(tx.toString());
2348
+ *
2349
+ * // Verify the transaction was successful
2350
+ * setTimeout(async () => {
2351
+ * const transaction = await programManager.networkClient.getTransaction(tx.id());
2352
+ * assert(transaction.id() === tx.id());
2353
+ * }, 10000);
1977
2354
  */
1978
- async buildTransferTransaction(amount, recipient, transferType, fee, privateFee, recordSearchParams, amountRecord, feeRecord, privateKey, offlineQuery) {
2355
+ async buildTransferTransaction(amount, recipient, transferType, priorityFee, privateFee, recordSearchParams, amountRecord, feeRecord, privateKey, offlineQuery) {
1979
2356
  // Validate the transfer type
1980
2357
  transferType = validateTransferType(transferType);
1981
2358
  // Get the private key from the account if it is not provided in the parameters
1982
2359
  let executionPrivateKey = privateKey;
1983
- if (typeof executionPrivateKey === "undefined" && typeof this.account !== "undefined") {
2360
+ if (typeof executionPrivateKey === "undefined" &&
2361
+ typeof this.account !== "undefined") {
1984
2362
  executionPrivateKey = this.account.privateKey();
1985
2363
  }
1986
2364
  if (typeof executionPrivateKey === "undefined") {
1987
- throw ("No private key provided and no private key set in the ProgramManager");
2365
+ throw "No private key provided and no private key set in the ProgramManager";
1988
2366
  }
1989
2367
  // Get the proving and verifying keys from the key provider
1990
2368
  let feeKeys;
1991
2369
  let transferKeys;
1992
2370
  try {
1993
- feeKeys = privateFee ? await this.keyProvider.feePrivateKeys() : await this.keyProvider.feePublicKeys();
1994
- transferKeys = await this.keyProvider.transferKeys(transferType);
2371
+ feeKeys = privateFee
2372
+ ? await this.keyProvider.feePrivateKeys()
2373
+ : await this.keyProvider.feePublicKeys();
2374
+ transferKeys = (await this.keyProvider.transferKeys(transferType));
1995
2375
  }
1996
2376
  catch (e) {
1997
2377
  logAndThrow(`Error finding fee keys. Key finder response: '${e.message}'. Please ensure your key provider is configured correctly.`);
@@ -2004,57 +2384,87 @@ class ProgramManager {
2004
2384
  const nonces = [];
2005
2385
  if (requiresAmountRecord(transferType)) {
2006
2386
  // If the transfer type is private and requires an amount record, get it from the record provider
2007
- amountRecord = await this.getCreditsRecord(fee, [], amountRecord, recordSearchParams);
2387
+ amountRecord = (await this.getCreditsRecord(priorityFee, [], amountRecord, recordSearchParams));
2008
2388
  nonces.push(amountRecord.nonce());
2009
2389
  }
2010
2390
  else {
2011
2391
  amountRecord = undefined;
2012
2392
  }
2013
- feeRecord = privateFee ? await this.getCreditsRecord(fee, nonces, feeRecord, recordSearchParams) : undefined;
2393
+ feeRecord = privateFee
2394
+ ? (await this.getCreditsRecord(priorityFee, nonces, feeRecord, recordSearchParams))
2395
+ : undefined;
2014
2396
  }
2015
2397
  catch (e) {
2016
2398
  logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
2017
2399
  }
2018
- // Build an execution transaction and submit it to the network
2019
- return await ProgramManager$1.buildTransferTransaction(executionPrivateKey, amount, recipient, transferType, amountRecord, fee, feeRecord, this.host, transferProvingKey, transferVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
2400
+ // Build an execution transaction
2401
+ return await ProgramManager$1.buildTransferTransaction(executionPrivateKey, amount, recipient, transferType, amountRecord, priorityFee, feeRecord, this.host, transferProvingKey, transferVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
2020
2402
  }
2021
2403
  /**
2022
2404
  * Build a transfer_public transaction to transfer credits to another account for later submission to the Aleo network
2023
2405
  *
2024
2406
  * @param {number} amount The amount of credits to transfer
2025
2407
  * @param {string} recipient The recipient of the transfer
2026
- * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate'
2027
- * @param {number} fee The fee to pay for the transfer
2028
- * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
2029
- * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee
2030
- * records for the transfer transaction
2031
- * @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer
2032
- * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
2408
+ * @param {number} priorityFee The optional priority fee to be paid for the transfer
2033
2409
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
2034
2410
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
2035
- * @returns {Promise<string>} The transaction id of the transfer transaction
2411
+ * @returns {Promise<Transaction>} The transaction object
2412
+ *
2413
+ * @example
2414
+ * /// Import the mainnet version of the sdk.
2415
+ * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
2416
+ *
2417
+ * // Create a new NetworkClient, KeyProvider, and RecordProvider
2418
+ * const keyProvider = new AleoKeyProvider();
2419
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
2420
+ * keyProvider.useCache = true;
2421
+ *
2422
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions
2423
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
2424
+ * const tx = await programManager.buildTransferPublicTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0.2);
2425
+ * await programManager.networkClient.submitTransaction(tx.toString());
2426
+ *
2427
+ * // Verify the transaction was successful
2428
+ * setTimeout(async () => {
2429
+ * const transaction = await programManager.networkClient.getTransaction(tx.id());
2430
+ * assert(transaction.id() === tx.id());
2431
+ * }, 10000);
2036
2432
  */
2037
- async buildTransferPublicTransaction(amount, recipient, fee, privateKey, offlineQuery) {
2038
- return this.buildTransferTransaction(amount, recipient, "public", fee, false, undefined, undefined, undefined, privateKey, offlineQuery);
2433
+ async buildTransferPublicTransaction(amount, recipient, priorityFee, privateKey, offlineQuery) {
2434
+ return this.buildTransferTransaction(amount, recipient, "public", priorityFee, false, undefined, undefined, undefined, privateKey, offlineQuery);
2039
2435
  }
2040
2436
  /**
2041
2437
  * Build a transfer_public_as_signer transaction to transfer credits to another account for later submission to the Aleo network
2042
2438
  *
2043
2439
  * @param {number} amount The amount of credits to transfer
2044
2440
  * @param {string} recipient The recipient of the transfer
2045
- * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate'
2046
- * @param {number} fee The fee to pay for the transfer
2047
- * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
2048
- * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee
2049
- * records for the transfer transaction
2050
- * @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer
2051
- * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
2441
+ * @param {number} priorityFee The optional priority fee to be paid for the transfer
2052
2442
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
2053
2443
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
2054
- * @returns {Promise<string>} The transaction id of the transfer transaction
2444
+ * @returns {Promise<Transaction>} The transaction object
2445
+ *
2446
+ * @example
2447
+ * /// Import the mainnet version of the sdk.
2448
+ * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
2449
+ *
2450
+ * // Create a new NetworkClient, KeyProvider, and RecordProvider
2451
+ * const keyProvider = new AleoKeyProvider();
2452
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
2453
+ * keyProvider.useCache = true;
2454
+ *
2455
+ * // Initialize a program manager with the key provider to automatically fetch keys for executions
2456
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
2457
+ * const tx = await programManager.buildTransferPublicAsSignerTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0.2);
2458
+ * await programManager.networkClient.submitTransaction(tx.toString());
2459
+ *
2460
+ * // Verify the transaction was successful
2461
+ * setTimeout(async () => {
2462
+ * const transaction = await programManager.networkClient.getTransaction(tx.id());
2463
+ * assert(transaction.id() === tx.id());
2464
+ * }, 10000);
2055
2465
  */
2056
- async buildTransferPublicAsSignerTransaction(amount, recipient, fee, privateKey, offlineQuery) {
2057
- return this.buildTransferTransaction(amount, recipient, "public", fee, false, undefined, undefined, undefined, privateKey, offlineQuery);
2466
+ async buildTransferPublicAsSignerTransaction(amount, recipient, priorityFee, privateKey, offlineQuery) {
2467
+ return this.buildTransferTransaction(amount, recipient, "public", priorityFee, false, undefined, undefined, undefined, privateKey, offlineQuery);
2058
2468
  }
2059
2469
  /**
2060
2470
  * Transfer credits to another account
@@ -2062,36 +2472,63 @@ class ProgramManager {
2062
2472
  * @param {number} amount The amount of credits to transfer
2063
2473
  * @param {string} recipient The recipient of the transfer
2064
2474
  * @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate'
2065
- * @param {number} fee The fee to pay for the transfer
2475
+ * @param {number} priorityFee The optional priority fee to be paid for the transfer
2066
2476
  * @param {boolean} privateFee Use a private record to pay the fee. If false this will use the account's public credit balance
2067
- * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee
2068
- * records for the transfer transaction
2477
+ * @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee records for the transfer transaction
2069
2478
  * @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer
2070
2479
  * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
2071
2480
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
2072
2481
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
2073
- * @returns {Promise<string>} The transaction id of the transfer transaction
2482
+ * @returns {Promise<string>} The transaction id
2074
2483
  *
2075
2484
  * @example
2485
+ * /// Import the mainnet version of the sdk.
2486
+ * import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
2487
+ *
2076
2488
  * // Create a new NetworkClient, KeyProvider, and RecordProvider
2077
- * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
2078
2489
  * const keyProvider = new AleoKeyProvider();
2079
2490
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
2491
+ * keyProvider.useCache = true;
2080
2492
  *
2081
2493
  * // Initialize a program manager with the key provider to automatically fetch keys for executions
2082
2494
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
2083
- * await programManager.initialize();
2084
- * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "private", 0.2)
2085
- * const transaction = await programManager.networkClient.getTransaction(tx_id);
2495
+ * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "public", 0.2, false);
2496
+ *
2497
+ * // Verify the transaction was successful
2498
+ * setTimeout(async () => {
2499
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
2500
+ * assert(transaction.id() === tx_id);
2501
+ * }, 10000);
2086
2502
  */
2087
- async transfer(amount, recipient, transferType, fee, privateFee, recordSearchParams, amountRecord, feeRecord, privateKey, offlineQuery) {
2088
- const tx = await this.buildTransferTransaction(amount, recipient, transferType, fee, privateFee, recordSearchParams, amountRecord, feeRecord, privateKey, offlineQuery);
2503
+ async transfer(amount, recipient, transferType, priorityFee, privateFee, recordSearchParams, amountRecord, feeRecord, privateKey, offlineQuery) {
2504
+ const tx = (await this.buildTransferTransaction(amount, recipient, transferType, priorityFee, privateFee, recordSearchParams, amountRecord, feeRecord, privateKey, offlineQuery));
2505
+ let feeAddress;
2506
+ if (typeof privateKey !== "undefined") {
2507
+ feeAddress = Address.from_private_key(privateKey);
2508
+ }
2509
+ else if (this.account !== undefined) {
2510
+ feeAddress = this.account?.address();
2511
+ }
2512
+ else {
2513
+ throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
2514
+ }
2515
+ // Check if the account has sufficient credits to pay for the transaction
2516
+ await this.checkFee(feeAddress.to_string(), tx.feeAmount());
2089
2517
  return await this.networkClient.submitTransaction(tx);
2090
2518
  }
2091
2519
  /**
2092
2520
  * Build transaction to bond credits to a validator for later submission to the Aleo Network
2093
2521
  *
2522
+ * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing validator and is different from the address of the executor of this function, it will bond the credits to that validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator.
2523
+ * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
2524
+ * @param {number} amount The amount of credits to bond
2525
+ * @param {Partial<ExecuteOptions>} options - Override default execution options.
2526
+ * @returns {Promise<Transaction>} The transaction object
2527
+ *
2094
2528
  * @example
2529
+ * // Import the mainnet version of the sdk.
2530
+ * import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
2531
+ *
2095
2532
  * // Create a keyProvider to handle key management
2096
2533
  * const keyProvider = new AleoKeyProvider();
2097
2534
  * keyProvider.useCache = true;
@@ -2102,72 +2539,97 @@ class ProgramManager {
2102
2539
  *
2103
2540
  * // Create the bonding transaction object for later submission
2104
2541
  * const tx = await programManager.buildBondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
2105
- * console.log(tx);
2106
2542
  *
2107
2543
  * // The transaction can be later submitted to the network using the network client.
2108
- * const result = await programManager.networkClient.submitTransaction(tx);
2109
- *
2110
- * @returns string
2111
- * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the
2112
- * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently
2113
- * requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing
2114
- * validator and is different from the address of the executor of this function, it will bond the credits to that
2115
- * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator.
2116
- * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
2117
- * @param {number} amount The amount of credits to bond
2118
- * @param {Partial<ExecuteOptions>} options - Override default execution options.
2544
+ * await programManager.networkClient.submitTransaction(tx.toString());
2545
+ *
2546
+ * // Verify the transaction was successful
2547
+ * setTimeout(async () => {
2548
+ * const transaction = await programManager.networkClient.getTransaction(tx.id());
2549
+ * assert(transaction.id() === tx.id());
2550
+ * }, 10000);
2119
2551
  */
2120
2552
  async buildBondPublicTransaction(validator_address, withdrawal_address, amount, options = {}) {
2121
2553
  const scaledAmount = Math.trunc(amount * 1000000);
2122
- const { programName = "credits.aleo", functionName = "bond_public", fee = options.fee || 0.86, privateFee = false, inputs = [validator_address, withdrawal_address, `${scaledAmount.toString()}u64`], keySearchParams = new AleoKeyProviderParams({
2554
+ const { programName = "credits.aleo", functionName = "bond_public", priorityFee = options.priorityFee || 0, privateFee = false, inputs = [
2555
+ validator_address,
2556
+ withdrawal_address,
2557
+ `${scaledAmount.toString()}u64`,
2558
+ ], keySearchParams = new AleoKeyProviderParams({
2123
2559
  proverUri: CREDITS_PROGRAM_KEYS.bond_public.prover,
2124
2560
  verifierUri: CREDITS_PROGRAM_KEYS.bond_public.verifier,
2125
- cacheKey: "credits.aleo/bond_public"
2561
+ cacheKey: "credits.aleo/bond_public",
2126
2562
  }), program = this.creditsProgram(), ...additionalOptions } = options;
2127
2563
  const executeOptions = {
2128
2564
  programName,
2129
2565
  functionName,
2130
- fee,
2566
+ priorityFee,
2131
2567
  privateFee,
2132
2568
  inputs,
2133
2569
  keySearchParams,
2134
- ...additionalOptions
2570
+ ...additionalOptions,
2135
2571
  };
2136
2572
  return await this.buildExecutionTransaction(executeOptions);
2137
2573
  }
2138
2574
  /**
2139
2575
  * Bond credits to validator.
2140
2576
  *
2577
+ * @param {string} validator_address Address of the validator to bond to, if this address is the same as the signer (i.e. the executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently requires a minimum of 1,000,000 credits to bond (subject to change). If the address is specified is an existing validator and is different from the address of the executor of this function, it will bond the credits to that validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator.
2578
+ * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
2579
+ * @param {number} amount The amount of credits to bond
2580
+ * @param {Options} options Options for the execution
2581
+ * @returns {Promise<string>} The transaction id
2582
+ *
2141
2583
  * @example
2584
+ * // Import the mainnet version of the sdk.
2585
+ * import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
2586
+ *
2142
2587
  * // Create a keyProvider to handle key management
2143
2588
  * const keyProvider = new AleoKeyProvider();
2144
2589
  * keyProvider.useCache = true;
2145
2590
  *
2146
2591
  * // Create a new ProgramManager with the key that will be used to bond credits
2147
2592
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2148
- * programManager.setAccount(new Account("YourPrivateKey"));
2149
2593
  *
2150
2594
  * // Create the bonding transaction
2151
- * const tx_id = await programManager.bondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
2152
- *
2153
- * @returns string
2154
- * @param {string} validator_address Address of the validator to bond to, if this address is the same as the signer (i.e. the
2155
- * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently
2156
- * requires a minimum of 1,000,000 credits to bond (subject to change). If the address is specified is an existing
2157
- * validator and is different from the address of the executor of this function, it will bond the credits to that
2158
- * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator.
2159
- * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
2160
- * @param {number} amount The amount of credits to bond
2161
- * @param {Options} options Options for the execution
2595
+ * tx_id = await programManager.bondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
2596
+ *
2597
+ * // Verify the transaction was successful
2598
+ * setTimeout(async () => {
2599
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
2600
+ * assert(transaction.id() === tx_id);
2601
+ * }, 10000);
2162
2602
  */
2163
2603
  async bondPublic(validator_address, withdrawal_address, amount, options = {}) {
2164
- const tx = await this.buildBondPublicTransaction(validator_address, withdrawal_address, amount, options);
2604
+ const tx = (await this.buildBondPublicTransaction(validator_address, withdrawal_address, amount, options));
2605
+ let feeAddress;
2606
+ if (typeof options.privateKey !== "undefined") {
2607
+ feeAddress = Address.from_private_key(options.privateKey);
2608
+ }
2609
+ else if (this.account !== undefined) {
2610
+ feeAddress = this.account?.address();
2611
+ }
2612
+ else {
2613
+ throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
2614
+ }
2615
+ // Check if the account has sufficient credits to pay for the transaction
2616
+ await this.checkFee(feeAddress.to_string(), tx.feeAmount());
2165
2617
  return await this.networkClient.submitTransaction(tx);
2166
2618
  }
2167
2619
  /**
2168
2620
  * Build a bond_validator transaction for later submission to the Aleo Network.
2169
2621
  *
2622
+ * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the executor of this function), it will attempt to bond the credits as a validator. If the address is specified is an existing validator and is different from the address of the executor of this function, it will bond the credits to that validator's staking committee as a delegator.
2623
+ * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
2624
+ * @param {number} amount The amount of credits to bond. A minimum of 10000 credits is required to bond as a delegator.
2625
+ * @param {number} commission The commission rate for the validator (must be between 0 and 100 - an error will be thrown if it is not)
2626
+ * @param {Partial<ExecuteOptions>} options - Override default execution options.
2627
+ * @returns {Promise<Transaction>} The transaction object
2628
+ *
2170
2629
  * @example
2630
+ * // Import the mainnet version of the sdk.
2631
+ * import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
2632
+ *
2171
2633
  * // Create a keyProvider to handle key management
2172
2634
  * const keyProvider = new AleoKeyProvider();
2173
2635
  * keyProvider.useCache = true;
@@ -2178,45 +2640,54 @@ class ProgramManager {
2178
2640
  *
2179
2641
  * // Create the bond validator transaction object for later use.
2180
2642
  * const tx = await programManager.buildBondValidatorTransaction("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
2181
- * console.log(tx);
2182
2643
  *
2183
2644
  * // The transaction can later be submitted to the network using the network client.
2184
- * const tx_id = await programManager.networkClient.submitTransaction(tx);
2185
- *
2186
- * @returns string
2187
- * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the
2188
- * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently
2189
- * requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing
2190
- * validator and is different from the address of the executor of this function, it will bond the credits to that
2191
- * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator.
2192
- * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
2193
- * @param {number} amount The amount of credits to bond
2194
- * @param {number} commission The commission rate for the validator (must be between 0 and 100 - an error will be thrown if it is not)
2195
- * @param {Partial<ExecuteOptions>} options - Override default execution options.
2645
+ * const tx_id = await programManager.networkClient.submitTransaction(tx.toString());
2646
+ *
2647
+ * // Verify the transaction was successful
2648
+ * setTimeout(async () => {
2649
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
2650
+ * assert(transaction.id() === tx_id);
2651
+ * }, 10000);
2196
2652
  */
2197
2653
  async buildBondValidatorTransaction(validator_address, withdrawal_address, amount, commission, options = {}) {
2198
2654
  const scaledAmount = Math.trunc(amount * 1000000);
2199
2655
  const adjustedCommission = Math.trunc(commission);
2200
- const { programName = "credits.aleo", functionName = "bond_validator", fee = options.fee || 0.86, privateFee = false, inputs = [validator_address, withdrawal_address, `${scaledAmount.toString()}u64`, `${adjustedCommission.toString()}u8`], keySearchParams = new AleoKeyProviderParams({
2656
+ const { programName = "credits.aleo", functionName = "bond_validator", priorityFee = options.priorityFee || 0, privateFee = false, inputs = [
2657
+ validator_address,
2658
+ withdrawal_address,
2659
+ `${scaledAmount.toString()}u64`,
2660
+ `${adjustedCommission.toString()}u8`,
2661
+ ], keySearchParams = new AleoKeyProviderParams({
2201
2662
  proverUri: CREDITS_PROGRAM_KEYS.bond_validator.prover,
2202
2663
  verifierUri: CREDITS_PROGRAM_KEYS.bond_validator.verifier,
2203
- cacheKey: "credits.aleo/bond_validator"
2664
+ cacheKey: "credits.aleo/bond_validator",
2204
2665
  }), program = this.creditsProgram(), ...additionalOptions } = options;
2205
2666
  const executeOptions = {
2206
2667
  programName,
2207
2668
  functionName,
2208
- fee,
2669
+ priorityFee,
2209
2670
  privateFee,
2210
2671
  inputs,
2211
2672
  keySearchParams,
2212
- ...additionalOptions
2673
+ ...additionalOptions,
2213
2674
  };
2214
2675
  return await this.buildExecutionTransaction(executeOptions);
2215
2676
  }
2216
2677
  /**
2217
2678
  * Build transaction to bond a validator.
2218
2679
  *
2680
+ * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing validator and is different from the address of the executor of this function, it will bond the credits to that validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator.
2681
+ * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
2682
+ * @param {number} amount The amount of credits to bond
2683
+ * @param {number} commission The commission rate for the validator (must be between 0 and 100 - an error will be thrown if it is not)
2684
+ * @param {Partial<ExecuteOptions>} options - Override default execution options.
2685
+ * @returns {Promise<string>} The transaction id
2686
+ *
2219
2687
  * @example
2688
+ * // Import the mainnet version of the sdk.
2689
+ * import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
2690
+ *
2220
2691
  * // Create a keyProvider to handle key management
2221
2692
  * const keyProvider = new AleoKeyProvider();
2222
2693
  * keyProvider.useCache = true;
@@ -2228,23 +2699,30 @@ class ProgramManager {
2228
2699
  * // Create the bonding transaction
2229
2700
  * const tx_id = await programManager.bondValidator("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
2230
2701
  *
2231
- * @returns string
2232
- * @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the
2233
- * executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently
2234
- * requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing
2235
- * validator and is different from the address of the executor of this function, it will bond the credits to that
2236
- * validator's staking committee as a delegator. A minimum of 10 credits is required to bond as a delegator.
2237
- * @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
2238
- * @param {number} amount The amount of credits to bond
2239
- * @param {number} commission The commission rate for the validator (must be between 0 and 100 - an error will be thrown if it is not)
2240
- * @param {Partial<ExecuteOptions>} options - Override default execution options.
2702
+ * // Verify the transaction was successful
2703
+ * setTimeout(async () => {
2704
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
2705
+ * assert(transaction.id() === tx_id);
2706
+ * }, 10000);
2241
2707
  */
2242
2708
  async bondValidator(validator_address, withdrawal_address, amount, commission, options = {}) {
2243
- const tx = await this.buildBondValidatorTransaction(validator_address, withdrawal_address, amount, commission, options);
2709
+ const tx = (await this.buildBondValidatorTransaction(validator_address, withdrawal_address, amount, commission, options));
2710
+ let feeAddress;
2711
+ if (typeof options.privateKey !== "undefined") {
2712
+ feeAddress = Address.from_private_key(options.privateKey);
2713
+ }
2714
+ else if (this.account !== undefined) {
2715
+ feeAddress = this.account?.address();
2716
+ }
2717
+ else {
2718
+ throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
2719
+ }
2720
+ // Check if the account has sufficient credits to pay for the transaction
2721
+ await this.checkFee(feeAddress.to_string(), tx.feeAmount());
2244
2722
  return await this.networkClient.submitTransaction(tx);
2245
2723
  }
2246
2724
  /**
2247
- * Build a transaction to unbond public credits from a validator in the Aleo network.
2725
+ * Build an unbond_public execution transaction to unbond credits from a validator in the Aleo network.
2248
2726
  *
2249
2727
  * @param {string} staker_address - The address of the staker who is unbonding the credits.
2250
2728
  * @param {number} amount - The amount of credits to unbond (scaled by 1,000,000).
@@ -2252,6 +2730,9 @@ class ProgramManager {
2252
2730
  * @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error message.
2253
2731
  *
2254
2732
  * @example
2733
+ * // Import the mainnet version of the sdk.
2734
+ * import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
2735
+ *
2255
2736
  * // Create a keyProvider to handle key management.
2256
2737
  * const keyProvider = new AleoKeyProvider();
2257
2738
  * keyProvider.useCache = true;
@@ -2259,33 +2740,51 @@ class ProgramManager {
2259
2740
  * // Create a new ProgramManager with the key that will be used to unbond credits.
2260
2741
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2261
2742
  * const tx = await programManager.buildUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 2000000);
2262
- * console.log(tx);
2263
2743
  *
2264
2744
  * // The transaction can be submitted later to the network using the network client.
2265
- * programManager.networkClient.submitTransaction(tx);
2745
+ * programManager.networkClient.submitTransaction(tx.toString());
2746
+ *
2747
+ * // Verify the transaction was successful
2748
+ * setTimeout(async () => {
2749
+ * const transaction = await programManager.networkClient.getTransaction(tx.id());
2750
+ * assert(transaction.id() === tx.id());
2751
+ * }, 10000);
2266
2752
  */
2267
2753
  async buildUnbondPublicTransaction(staker_address, amount, options = {}) {
2268
2754
  const scaledAmount = Math.trunc(amount * 1000000);
2269
- const { programName = "credits.aleo", functionName = "unbond_public", fee = options.fee || 1.3, privateFee = false, inputs = [staker_address, `${scaledAmount.toString()}u64`], keySearchParams = new AleoKeyProviderParams({
2755
+ const { programName = "credits.aleo", functionName = "unbond_public", priorityFee = options.priorityFee || 0, privateFee = false, inputs = [staker_address, `${scaledAmount.toString()}u64`], keySearchParams = new AleoKeyProviderParams({
2270
2756
  proverUri: CREDITS_PROGRAM_KEYS.unbond_public.prover,
2271
2757
  verifierUri: CREDITS_PROGRAM_KEYS.unbond_public.verifier,
2272
- cacheKey: "credits.aleo/unbond_public"
2758
+ cacheKey: "credits.aleo/unbond_public",
2273
2759
  }), program = this.creditsProgram(), ...additionalOptions } = options;
2274
2760
  const executeOptions = {
2275
2761
  programName,
2276
2762
  functionName,
2277
- fee,
2763
+ priorityFee,
2278
2764
  privateFee,
2279
2765
  inputs,
2280
2766
  keySearchParams,
2281
- ...additionalOptions
2767
+ ...additionalOptions,
2282
2768
  };
2283
2769
  return this.buildExecutionTransaction(executeOptions);
2284
2770
  }
2285
2771
  /**
2286
- * Unbond a specified amount of staked credits.
2772
+ * Unbond a specified amount of staked credits. If the address of the executor of this function is an existing
2773
+ * validator, it will subtract this amount of credits from the validator's staked credits. If there are less than
2774
+ * 1,000,000 credits staked pool after the unbond, the validator will be removed from the validator set. If the
2775
+ * address of the executor of this function is not a validator and has credits bonded as a delegator, it will
2776
+ * subtract this amount of credits from the delegator's staked credits. If there are less than 10 credits bonded
2777
+ * after the unbond operation, the delegator will be removed from the validator's staking pool.
2778
+ *
2779
+ * @param {string} staker_address Address of the staker who is unbonding the credits
2780
+ * @param {number} amount Amount of credits to unbond.
2781
+ * @param {ExecuteOptions} options Options for the execution
2782
+ * @returns {Promise<string>} The transaction id
2287
2783
  *
2288
2784
  * @example
2785
+ * // Import the mainnet version of the sdk.
2786
+ * import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
2787
+ *
2289
2788
  * // Create a keyProvider to handle key management
2290
2789
  * const keyProvider = new AleoKeyProvider();
2291
2790
  * keyProvider.useCache = true;
@@ -2294,21 +2793,29 @@ class ProgramManager {
2294
2793
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2295
2794
  * programManager.setAccount(new Account("YourPrivateKey"));
2296
2795
  *
2297
- * // Create the bonding transaction and send it to the network
2796
+ * // Create the unbond_public transaction and send it to the network
2298
2797
  * const tx_id = await programManager.unbondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 10);
2299
2798
  *
2300
- * @returns string
2301
- * @param {string} staker_address Address of the staker who is unbonding the credits
2302
- * @param {number} amount Amount of credits to unbond. If the address of the executor of this function is an
2303
- * existing validator, it will subtract this amount of credits from the validator's staked credits. If there are
2304
- * less than 1,000,000 credits staked pool after the unbond, the validator will be removed from the validator set.
2305
- * If the address of the executor of this function is not a validator and has credits bonded as a delegator, it will
2306
- * subtract this amount of credits from the delegator's staked credits. If there are less than 10 credits bonded
2307
- * after the unbond operation, the delegator will be removed from the validator's staking pool.
2308
- * @param {ExecuteOptions} options Options for the execution
2799
+ * // Verify the transaction was successful
2800
+ * setTimeout(async () => {
2801
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
2802
+ * assert(transaction.id() === tx_id);
2803
+ * }, 10000);
2309
2804
  */
2310
2805
  async unbondPublic(staker_address, amount, options = {}) {
2311
- const tx = await this.buildUnbondPublicTransaction(staker_address, amount, options);
2806
+ const tx = (await this.buildUnbondPublicTransaction(staker_address, amount, options));
2807
+ let feeAddress;
2808
+ if (typeof options.privateKey !== "undefined") {
2809
+ feeAddress = Address.from_private_key(options.privateKey);
2810
+ }
2811
+ else if (this.account !== undefined) {
2812
+ feeAddress = this.account?.address();
2813
+ }
2814
+ else {
2815
+ throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
2816
+ }
2817
+ // Check if the account has sufficient credits to pay for the transaction
2818
+ await this.checkFee(feeAddress.to_string(), tx.feeAmount());
2312
2819
  return await this.networkClient.submitTransaction(tx);
2313
2820
  }
2314
2821
  /**
@@ -2319,6 +2826,9 @@ class ProgramManager {
2319
2826
  * @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error message.
2320
2827
  *
2321
2828
  * @example
2829
+ * // Import the mainnet version of the sdk.
2830
+ * import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
2831
+ *
2322
2832
  * // Create a keyProvider to handle key management
2323
2833
  * const keyProvider = new AleoKeyProvider();
2324
2834
  * keyProvider.useCache = true;
@@ -2326,35 +2836,48 @@ class ProgramManager {
2326
2836
  * // Create a new ProgramManager with the key that will be used to claim unbonded credits.
2327
2837
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2328
2838
  *
2329
- * // Create the claim unbonded transaction object for later use.
2839
+ * // Create the claim_unbond_public transaction object for later use.
2330
2840
  * const tx = await programManager.buildClaimUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j");
2331
- * console.log(tx);
2332
2841
  *
2333
2842
  * // The transaction can be submitted later to the network using the network client.
2334
- * programManager.networkClient.submitTransaction(tx);
2843
+ * programManager.networkClient.submitTransaction(tx.toString());
2844
+ *
2845
+ * // Verify the transaction was successful
2846
+ * setTimeout(async () => {
2847
+ * const transaction = await programManager.networkClient.getTransaction(tx.id());
2848
+ * assert(transaction.id() === tx.id());
2849
+ * }, 10000);
2335
2850
  */
2336
2851
  async buildClaimUnbondPublicTransaction(staker_address, options = {}) {
2337
- const { programName = "credits.aleo", functionName = "claim_unbond_public", fee = options.fee || 2, privateFee = false, inputs = [staker_address], keySearchParams = new AleoKeyProviderParams({
2852
+ const { programName = "credits.aleo", functionName = "claim_unbond_public", priorityFee = options.priorityFee || 0, privateFee = false, inputs = [staker_address], keySearchParams = new AleoKeyProviderParams({
2338
2853
  proverUri: CREDITS_PROGRAM_KEYS.claim_unbond_public.prover,
2339
2854
  verifierUri: CREDITS_PROGRAM_KEYS.claim_unbond_public.verifier,
2340
- cacheKey: "credits.aleo/claim_unbond_public"
2855
+ cacheKey: "credits.aleo/claim_unbond_public",
2341
2856
  }), program = this.creditsProgram(), ...additionalOptions } = options;
2342
2857
  const executeOptions = {
2343
2858
  programName,
2344
2859
  functionName,
2345
- fee,
2860
+ priorityFee,
2346
2861
  privateFee,
2347
2862
  inputs,
2348
2863
  keySearchParams,
2349
- ...additionalOptions
2864
+ ...additionalOptions,
2350
2865
  };
2866
+ // Check if the account has sufficient credits to pay for the transaction
2351
2867
  return await this.buildExecutionTransaction(executeOptions);
2352
2868
  }
2353
2869
  /**
2354
2870
  * Claim unbonded credits. If credits have been unbonded by the account executing this function, this method will
2355
2871
  * claim them and add them to the public balance of the account.
2356
2872
  *
2873
+ * @param {string} staker_address Address of the staker who is claiming the credits
2874
+ * @param {ExecuteOptions} options
2875
+ * @returns {Promise<string>} The transaction id
2876
+ *
2357
2877
  * @example
2878
+ * // Import the mainnet version of the sdk.
2879
+ * import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
2880
+ *
2358
2881
  * // Create a keyProvider to handle key management
2359
2882
  * const keyProvider = new AleoKeyProvider();
2360
2883
  * keyProvider.useCache = true;
@@ -2363,15 +2886,29 @@ class ProgramManager {
2363
2886
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2364
2887
  * programManager.setAccount(new Account("YourPrivateKey"));
2365
2888
  *
2366
- * // Create the bonding transaction
2889
+ * // Create the claim_unbond_public transaction
2367
2890
  * const tx_id = await programManager.claimUnbondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j");
2368
2891
  *
2369
- * @param {string} staker_address Address of the staker who is claiming the credits
2370
- * @param {ExecuteOptions} options
2371
- * @returns string
2892
+ * // Verify the transaction was successful
2893
+ * setTimeout(async () => {
2894
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
2895
+ * assert(transaction.id() === tx_id);
2896
+ * }, 10000);
2372
2897
  */
2373
2898
  async claimUnbondPublic(staker_address, options = {}) {
2374
- const tx = await this.buildClaimUnbondPublicTransaction(staker_address, options);
2899
+ const tx = (await this.buildClaimUnbondPublicTransaction(staker_address, options));
2900
+ let feeAddress;
2901
+ if (typeof options.privateKey !== "undefined") {
2902
+ feeAddress = Address.from_private_key(options.privateKey);
2903
+ }
2904
+ else if (this.account !== undefined) {
2905
+ feeAddress = this.account?.address();
2906
+ }
2907
+ else {
2908
+ throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
2909
+ }
2910
+ // Check if the account has sufficient credits to pay for the transaction
2911
+ await this.checkFee(feeAddress.to_string(), tx.feeAmount());
2375
2912
  return await this.networkClient.submitTransaction(tx);
2376
2913
  }
2377
2914
  /**
@@ -2385,41 +2922,49 @@ class ProgramManager {
2385
2922
  * 1. Allow a validator to leave the committee, by closing themselves to stakers and then unbonding all of their stakers.
2386
2923
  * 2. Allow a validator to maintain their % of stake, by closing themselves to allowing more stakers to bond to them.
2387
2924
  *
2925
+ * @param {boolean} validator_state
2926
+ * @param {Partial<ExecuteOptions>} options - Override default execution options
2927
+ * @returns {Promise<Transaction>} The transaction object
2928
+ *
2388
2929
  * @example
2930
+ * // Import the mainnet version of the sdk.
2931
+ * import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
2932
+ *
2389
2933
  * // Create a keyProvider to handle key management
2390
2934
  * const keyProvider = new AleoKeyProvider();
2391
2935
  * keyProvider.useCache = true;
2392
2936
  *
2393
2937
  * // Create a new ProgramManager with the key that will be used to bond credits
2394
2938
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2395
- * programManager.setAccount(new Account("ValidatorPrivateKey"));
2396
2939
  *
2397
- * // Create the bonding transaction
2940
+ * // Create the set_validator_state transaction
2398
2941
  * const tx = await programManager.buildSetValidatorStateTransaction(true);
2399
2942
  *
2400
2943
  * // The transaction can be submitted later to the network using the network client.
2401
- * programManager.networkClient.submitTransaction(tx);
2944
+ * programManager.networkClient.submitTransaction(tx.toString());
2402
2945
  *
2403
- * @returns string
2404
- * @param {boolean} validator_state
2405
- * @param {Partial<ExecuteOptions>} options - Override default execution options
2946
+ * // Verify the transaction was successful
2947
+ * setTimeout(async () => {
2948
+ * const transaction = await programManager.networkClient.getTransaction(tx.id());
2949
+ * assert(transaction.id() === tx.id());
2950
+ * }, 10000);
2406
2951
  */
2407
2952
  async buildSetValidatorStateTransaction(validator_state, options = {}) {
2408
- const { programName = "credits.aleo", functionName = "set_validator_state", fee = 1, privateFee = false, inputs = [validator_state.toString()], keySearchParams = new AleoKeyProviderParams({
2953
+ const { programName = "credits.aleo", functionName = "set_validator_state", priorityFee = 0, privateFee = false, inputs = [validator_state.toString()], keySearchParams = new AleoKeyProviderParams({
2409
2954
  proverUri: CREDITS_PROGRAM_KEYS.set_validator_state.prover,
2410
2955
  verifierUri: CREDITS_PROGRAM_KEYS.set_validator_state.verifier,
2411
- cacheKey: "credits.aleo/set_validator_state"
2956
+ cacheKey: "credits.aleo/set_validator_state",
2412
2957
  }), ...additionalOptions } = options;
2413
2958
  const executeOptions = {
2414
2959
  programName,
2415
2960
  functionName,
2416
- fee,
2961
+ priorityFee,
2417
2962
  privateFee,
2418
2963
  inputs,
2419
2964
  keySearchParams,
2420
- ...additionalOptions
2965
+ ...additionalOptions,
2421
2966
  };
2422
- return await this.execute(executeOptions);
2967
+ return await this.buildExecutionTransaction(executeOptions);
2423
2968
  }
2424
2969
  /**
2425
2970
  * Submit a set_validator_state transaction to the Aleo Network.
@@ -2432,24 +2977,44 @@ class ProgramManager {
2432
2977
  * 1. Allow a validator to leave the committee, by closing themselves to stakers and then unbonding all of their stakers.
2433
2978
  * 2. Allow a validator to maintain their % of stake, by closing themselves to allowing more stakers to bond to them.
2434
2979
  *
2980
+ * @param {boolean} validator_state
2981
+ * @param {Partial<ExecuteOptions>} options - Override default execution options
2982
+ * @returns {Promise<string>} The transaction id
2983
+ *
2435
2984
  * @example
2985
+ * // Import the mainnet version of the sdk.
2986
+ * import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
2987
+ *
2436
2988
  * // Create a keyProvider to handle key management
2437
2989
  * const keyProvider = new AleoKeyProvider();
2438
2990
  * keyProvider.useCache = true;
2439
2991
  *
2440
2992
  * // Create a new ProgramManager with the key that will be used to bond credits
2441
2993
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2442
- * programManager.setAccount(new Account("ValidatorPrivateKey"));
2443
2994
  *
2444
- * // Create the bonding transaction
2995
+ * // Create the set_validator_state transaction
2445
2996
  * const tx_id = await programManager.setValidatorState(true);
2446
2997
  *
2447
- * @returns string
2448
- * @param {boolean} validator_state
2449
- * @param {Partial<ExecuteOptions>} options - Override default execution options
2998
+ * // Verify the transaction was successful
2999
+ * setTimeout(async () => {
3000
+ * const transaction = await programManager.networkClient.getTransaction(tx_id);
3001
+ * assert(transaction.id() === tx_id);
3002
+ * }, 10000);
2450
3003
  */
2451
3004
  async setValidatorState(validator_state, options = {}) {
2452
- const tx = await this.buildSetValidatorStateTransaction(validator_state, options);
3005
+ const tx = (await this.buildSetValidatorStateTransaction(validator_state, options));
3006
+ let feeAddress;
3007
+ if (typeof options.privateKey !== "undefined") {
3008
+ feeAddress = Address.from_private_key(options.privateKey);
3009
+ }
3010
+ else if (this.account !== undefined) {
3011
+ feeAddress = this.account?.address();
3012
+ }
3013
+ else {
3014
+ throw Error("No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.");
3015
+ }
3016
+ // Check if the account has sufficient credits to pay for the transaction
3017
+ await this.checkFee(feeAddress.to_string(), tx.feeAmount());
2453
3018
  return this.networkClient.submitTransaction(tx);
2454
3019
  }
2455
3020
  /**
@@ -2460,7 +3025,7 @@ class ProgramManager {
2460
3025
  */
2461
3026
  verifyExecution(executionResponse) {
2462
3027
  try {
2463
- const execution = executionResponse.getExecution();
3028
+ const execution = (executionResponse.getExecution());
2464
3029
  const function_id = executionResponse.getFunctionId();
2465
3030
  const program = executionResponse.getProgram();
2466
3031
  const verifyingKey = executionResponse.getVerifyingKey();
@@ -2505,7 +3070,9 @@ class ProgramManager {
2505
3070
  // Internal utility function for getting a credits.aleo record
2506
3071
  async getCreditsRecord(amount, nonces, record, params) {
2507
3072
  try {
2508
- return record instanceof RecordPlaintext ? record : RecordPlaintext.fromString(record);
3073
+ return record instanceof RecordPlaintext
3074
+ ? record
3075
+ : RecordPlaintext.fromString(record);
2509
3076
  }
2510
3077
  catch (e) {
2511
3078
  try {
@@ -2524,9 +3091,10 @@ function requiresAmountRecord(transferType) {
2524
3091
  }
2525
3092
  // Validate the transfer type
2526
3093
  function validateTransferType(transferType) {
2527
- return VALID_TRANSFER_TYPES.has(transferType) ? transferType :
2528
- logAndThrow(`Invalid transfer type '${transferType}'. Valid transfer types are 'private', 'privateToPublic', 'public', and 'publicToPrivate'.`);
3094
+ return VALID_TRANSFER_TYPES.has(transferType)
3095
+ ? transferType
3096
+ : logAndThrow(`Invalid transfer type '${transferType}'. Valid transfer types are 'private', 'privateToPublic', 'public', and 'publicToPrivate'.`);
2529
3097
  }
2530
3098
 
2531
3099
  export { AleoKeyProvider as A, CREDITS_PROGRAM_KEYS as C, KEY_STORE as K, ProgramManager as P, VALID_TRANSFER_TYPES as V, AleoKeyProviderParams as a, AleoNetworkClient as b, PRIVATE_TRANSFER as c, PRIVATE_TO_PUBLIC_TRANSFER as d, PRIVATE_TRANSFER_TYPES as e, PUBLIC_TRANSFER as f, PUBLIC_TRANSFER_AS_SIGNER as g, PUBLIC_TO_PRIVATE_TRANSFER as h, logAndThrow as l };
2532
- //# sourceMappingURL=program-manager-CjvnOyfn.js.map
3100
+ //# sourceMappingURL=program-manager-BuK9g9xJ.js.map