@provablehq/sdk 0.8.6 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mainnet/account.d.ts +2 -2
- package/dist/mainnet/browser.js +6 -6
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/network-client.d.ts +1 -1
- package/dist/mainnet/node.js +1 -1
- package/dist/mainnet/{program-manager-ZQyvNmJs.js → program-manager-D0WpABBc.js} +308 -138
- package/dist/mainnet/program-manager-D0WpABBc.js.map +1 -0
- package/dist/mainnet/program-manager.d.ts +305 -135
- package/dist/mainnet/worker.js +1 -1
- package/dist/testnet/account.d.ts +2 -2
- package/dist/testnet/browser.js +6 -6
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/network-client.d.ts +1 -1
- package/dist/testnet/node.js +1 -1
- package/dist/testnet/{program-manager-CjvnOyfn.js → program-manager-CVoUpH8X.js} +308 -138
- package/dist/testnet/program-manager-CVoUpH8X.js.map +1 -0
- package/dist/testnet/program-manager.d.ts +305 -135
- package/dist/testnet/worker.js +1 -1
- package/package.json +3 -2
- package/dist/mainnet/program-manager-ZQyvNmJs.js.map +0 -1
- package/dist/testnet/program-manager-CjvnOyfn.js.map +0 -1
|
@@ -38,7 +38,7 @@ async function post(url, options) {
|
|
|
38
38
|
* @param {string} host
|
|
39
39
|
* @example
|
|
40
40
|
* // Connection to a local node
|
|
41
|
-
* const localNetworkClient = new AleoNetworkClient("http://
|
|
41
|
+
* const localNetworkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined, account);
|
|
42
42
|
*
|
|
43
43
|
* // Connection to a public beacon node
|
|
44
44
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
@@ -56,7 +56,7 @@ 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.
|
|
59
|
+
"X-Aleo-SDK-Version": "0.8.7",
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -1517,27 +1517,37 @@ class ProgramManager {
|
|
|
1517
1517
|
* @param {string} program Program source code
|
|
1518
1518
|
* @param {number} fee Fee to pay for the transaction
|
|
1519
1519
|
* @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
|
|
1520
|
+
* @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for searching for a record to use pay the deployment fee
|
|
1522
1521
|
* @param {string | RecordPlaintext | undefined} feeRecord Optional Fee record to use for the transaction
|
|
1523
1522
|
* @param {PrivateKey | undefined} privateKey Optional private key to use for the transaction
|
|
1524
1523
|
* @returns {string} The transaction id of the deployed program or a failure message from the network
|
|
1525
1524
|
*
|
|
1526
1525
|
* @example
|
|
1526
|
+
* /// Import the mainnet version of the sdk.
|
|
1527
|
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
1528
|
+
*
|
|
1527
1529
|
* // Create a new NetworkClient, KeyProvider, and RecordProvider
|
|
1528
|
-
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
1529
1530
|
* const keyProvider = new AleoKeyProvider();
|
|
1530
1531
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
1532
|
+
* keyProvider.useCache = true;
|
|
1531
1533
|
*
|
|
1532
1534
|
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
1533
1535
|
* 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
1536
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
1537
|
+
* programManager.setAccount(Account);
|
|
1535
1538
|
*
|
|
1536
1539
|
* // Define a fee in credits
|
|
1537
1540
|
* const fee = 1.2;
|
|
1538
1541
|
*
|
|
1539
1542
|
* // Create the deployment transaction.
|
|
1540
1543
|
* const tx = await programManager.buildDeploymentTransaction(program, fee, false);
|
|
1544
|
+
* await programManager.networkClient.submitTransaction(tx);
|
|
1545
|
+
*
|
|
1546
|
+
* // Verify the transaction was successful
|
|
1547
|
+
* setTimeout(async () => {
|
|
1548
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
1549
|
+
* assert(transaction.id() === tx.id());
|
|
1550
|
+
* }, 20000);
|
|
1541
1551
|
*/
|
|
1542
1552
|
async buildDeploymentTransaction(program, fee, privateFee, recordSearchParams, feeRecord, privateKey) {
|
|
1543
1553
|
// Ensure the program is valid and does not exist on the network
|
|
@@ -1599,17 +1609,19 @@ class ProgramManager {
|
|
|
1599
1609
|
* @param {string} program Program source code
|
|
1600
1610
|
* @param {number} fee Fee to pay for the transaction
|
|
1601
1611
|
* @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
|
|
1603
|
-
* pay the deployment fee
|
|
1612
|
+
* @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for searching for a record to used pay the deployment fee
|
|
1604
1613
|
* @param {string | RecordPlaintext | undefined} feeRecord Optional Fee record to use for the transaction
|
|
1605
1614
|
* @param {PrivateKey | undefined} privateKey Optional private key to use for the transaction
|
|
1606
1615
|
* @returns {string} The transaction id of the deployed program or a failure message from the network
|
|
1607
1616
|
*
|
|
1608
1617
|
* @example
|
|
1618
|
+
* /// Import the mainnet version of the sdk.
|
|
1619
|
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
1620
|
+
*
|
|
1609
1621
|
* // Create a new NetworkClient, KeyProvider, and RecordProvider
|
|
1610
|
-
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
1611
1622
|
* const keyProvider = new AleoKeyProvider();
|
|
1612
1623
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
1624
|
+
* keyProvider.useCache = true;
|
|
1613
1625
|
*
|
|
1614
1626
|
* // Initialize a program manager with the key provider to automatically fetch keys for deployments
|
|
1615
1627
|
* 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";
|
|
@@ -1622,7 +1634,10 @@ class ProgramManager {
|
|
|
1622
1634
|
* const tx_id = await programManager.deploy(program, fee, false);
|
|
1623
1635
|
*
|
|
1624
1636
|
* // Verify the transaction was successful
|
|
1625
|
-
*
|
|
1637
|
+
* setTimeout(async () => {
|
|
1638
|
+
* const transaction = await programManager.networkClient.getTransaction(tx_id);
|
|
1639
|
+
* assert(transaction.id() === tx_id);
|
|
1640
|
+
* }, 20000);
|
|
1626
1641
|
*/
|
|
1627
1642
|
async deploy(program, fee, privateFee, recordSearchParams, feeRecord, privateKey) {
|
|
1628
1643
|
const tx = await this.buildDeploymentTransaction(program, fee, privateFee, recordSearchParams, feeRecord, privateKey);
|
|
@@ -1635,17 +1650,19 @@ class ProgramManager {
|
|
|
1635
1650
|
* @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error.
|
|
1636
1651
|
*
|
|
1637
1652
|
* @example
|
|
1653
|
+
* /// Import the mainnet version of the sdk.
|
|
1654
|
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
1655
|
+
*
|
|
1638
1656
|
* // 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
1657
|
* const keyProvider = new AleoKeyProvider();
|
|
1641
|
-
* keyProvider.useCache = true;
|
|
1642
1658
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
1659
|
+
* keyProvider.useCache = true;
|
|
1643
1660
|
*
|
|
1644
1661
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
1645
1662
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
1646
1663
|
*
|
|
1647
1664
|
* // Build and execute the transaction
|
|
1648
|
-
* const
|
|
1665
|
+
* const tx = await programManager.buildExecutionTransaction({
|
|
1649
1666
|
* programName: "hello_hello.aleo",
|
|
1650
1667
|
* functionName: "hello_hello",
|
|
1651
1668
|
* fee: 0.020,
|
|
@@ -1653,7 +1670,15 @@ class ProgramManager {
|
|
|
1653
1670
|
* inputs: ["5u32", "5u32"],
|
|
1654
1671
|
* keySearchParams: { "cacheKey": "hello_hello:hello" }
|
|
1655
1672
|
* });
|
|
1656
|
-
*
|
|
1673
|
+
*
|
|
1674
|
+
* // Submit the transaction to the network
|
|
1675
|
+
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
1676
|
+
*
|
|
1677
|
+
* // Verify the transaction was successful
|
|
1678
|
+
* setTimeout(async () => {
|
|
1679
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
1680
|
+
* assert(transaction.id() === tx.id());
|
|
1681
|
+
* }, 10000);
|
|
1657
1682
|
*/
|
|
1658
1683
|
async buildExecutionTransaction(options) {
|
|
1659
1684
|
// Destructure the options object to access the parameters
|
|
@@ -1725,20 +1750,22 @@ class ProgramManager {
|
|
|
1725
1750
|
* Builds an execution transaction for submission to the Aleo network.
|
|
1726
1751
|
*
|
|
1727
1752
|
* @param {ExecuteOptions} options - The options for the execution transaction.
|
|
1728
|
-
* @returns {Promise<
|
|
1753
|
+
* @returns {Promise<string>} - The transaction id
|
|
1729
1754
|
*
|
|
1730
1755
|
* @example
|
|
1756
|
+
* /// Import the mainnet version of the sdk.
|
|
1757
|
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
1758
|
+
*
|
|
1731
1759
|
* // 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
1760
|
* const keyProvider = new AleoKeyProvider();
|
|
1734
|
-
* keyProvider.useCache = true;
|
|
1735
1761
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
1762
|
+
* keyProvider.useCache = true;
|
|
1736
1763
|
*
|
|
1737
1764
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
1738
1765
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
1739
1766
|
*
|
|
1740
1767
|
* // Build and execute the transaction
|
|
1741
|
-
* const
|
|
1768
|
+
* const tx_id = await programManager.execute({
|
|
1742
1769
|
* programName: "hello_hello.aleo",
|
|
1743
1770
|
* functionName: "hello_hello",
|
|
1744
1771
|
* fee: 0.020,
|
|
@@ -1746,7 +1773,12 @@ class ProgramManager {
|
|
|
1746
1773
|
* inputs: ["5u32", "5u32"],
|
|
1747
1774
|
* keySearchParams: { "cacheKey": "hello_hello:hello" }
|
|
1748
1775
|
* });
|
|
1749
|
-
*
|
|
1776
|
+
*
|
|
1777
|
+
* // Verify the transaction was successful
|
|
1778
|
+
* setTimeout(async () => {
|
|
1779
|
+
* const transaction = await programManager.networkClient.getTransaction(tx_id);
|
|
1780
|
+
* assert(transaction.id() === tx_id);
|
|
1781
|
+
* }, 10000);
|
|
1750
1782
|
*/
|
|
1751
1783
|
async execute(options) {
|
|
1752
1784
|
const tx = await this.buildExecutionTransaction(options);
|
|
@@ -1758,23 +1790,22 @@ class ProgramManager {
|
|
|
1758
1790
|
* @param {string} program Program source code containing the function to be executed
|
|
1759
1791
|
* @param {string} function_name Function name to execute
|
|
1760
1792
|
* @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.
|
|
1793
|
+
* @param {number} proveExecution Whether to prove the execution of the function and return an execution transcript that contains the proof.
|
|
1763
1794
|
* @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
|
|
1795
|
+
* @param {KeySearchParams | undefined} keySearchParams Optional parameters for finding the matching proving & verifying keys for the function
|
|
1766
1796
|
* @param {ProvingKey | undefined} provingKey Optional proving key to use for the transaction
|
|
1767
1797
|
* @param {VerifyingKey | undefined} verifyingKey Optional verifying key to use for the transaction
|
|
1768
1798
|
* @param {PrivateKey | undefined} privateKey Optional private key to use for the transaction
|
|
1769
1799
|
* @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
|
|
1770
|
-
* @returns {Promise<
|
|
1800
|
+
* @returns {Promise<ExecutionResponse>} The execution response containing the outputs of the function and the proof if the program is proved.
|
|
1771
1801
|
*
|
|
1772
1802
|
* @example
|
|
1773
|
-
*
|
|
1803
|
+
* /// Import the mainnet version of the sdk used to build executions.
|
|
1804
|
+
* import { Account, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
1774
1805
|
*
|
|
1775
1806
|
* /// Create the source for the "helloworld" program
|
|
1776
1807
|
* 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();
|
|
1808
|
+
* const programManager = new ProgramManager(undefined, undefined, undefined);
|
|
1778
1809
|
*
|
|
1779
1810
|
* /// Create a temporary account for the execution of the program
|
|
1780
1811
|
* const account = new Account();
|
|
@@ -1816,12 +1847,32 @@ class ProgramManager {
|
|
|
1816
1847
|
* @param {RecordPlaintext | string} recordTwo Second credits record to join
|
|
1817
1848
|
* @param {number} fee Fee in credits pay for the join transaction
|
|
1818
1849
|
* @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
|
|
1850
|
+
* @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the fee record to use to pay the fee for the join transaction
|
|
1821
1851
|
* @param {RecordPlaintext | string | undefined} feeRecord Fee record to use for the join transaction
|
|
1822
1852
|
* @param {PrivateKey | undefined} privateKey Private key to use for the join transaction
|
|
1823
1853
|
* @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
|
|
1824
|
-
* @returns {Promise<string>}
|
|
1854
|
+
* @returns {Promise<string>} The transaction id
|
|
1855
|
+
*
|
|
1856
|
+
* @example
|
|
1857
|
+
* /// Import the mainnet version of the sdk.
|
|
1858
|
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
1859
|
+
*
|
|
1860
|
+
* // Create a new NetworkClient, KeyProvider, and RecordProvider
|
|
1861
|
+
* const keyProvider = new AleoKeyProvider();
|
|
1862
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
1863
|
+
* keyProvider.useCache = true;
|
|
1864
|
+
*
|
|
1865
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
1866
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
1867
|
+
* const record_1 = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
|
|
1868
|
+
* const record_2 = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 1540945439182663264862696551825005342995406165131907382295858612069623286213group.public}"
|
|
1869
|
+
* const tx_id = await programManager.join(record_1, record_2, 0.05, false);
|
|
1870
|
+
*
|
|
1871
|
+
* // Verify the transaction was successful
|
|
1872
|
+
* setTimeout(async () => {
|
|
1873
|
+
* const transaction = await programManager.networkClient.getTransaction(tx_id);
|
|
1874
|
+
* assert(transaction.id() === tx_id);
|
|
1875
|
+
* }, 10000);
|
|
1825
1876
|
*/
|
|
1826
1877
|
async join(recordOne, recordTwo, fee, privateFee, recordSearchParams, feeRecord, privateKey, offlineQuery) {
|
|
1827
1878
|
// Get the private key from the account if it is not provided in the parameters
|
|
@@ -1870,20 +1921,27 @@ class ProgramManager {
|
|
|
1870
1921
|
* @param {RecordPlaintext | string} amountRecord Amount record to use for the split transaction
|
|
1871
1922
|
* @param {PrivateKey | undefined} privateKey Optional private key to use for the split transaction
|
|
1872
1923
|
* @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
|
|
1873
|
-
* @returns {Promise<string>}
|
|
1924
|
+
* @returns {Promise<string>} The transaction id
|
|
1874
1925
|
*
|
|
1875
1926
|
* @example
|
|
1927
|
+
* /// Import the mainnet version of the sdk.
|
|
1928
|
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
1929
|
+
*
|
|
1876
1930
|
* // Create a new NetworkClient, KeyProvider, and RecordProvider
|
|
1877
|
-
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
1878
1931
|
* const keyProvider = new AleoKeyProvider();
|
|
1879
1932
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
1933
|
+
* keyProvider.useCache = true;
|
|
1880
1934
|
*
|
|
1881
1935
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
1882
|
-
* const programName = "hello_hello.aleo";
|
|
1883
1936
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
1884
1937
|
* const record = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
|
|
1885
1938
|
* const tx_id = await programManager.split(25000000, record);
|
|
1886
|
-
*
|
|
1939
|
+
*
|
|
1940
|
+
* // Verify the transaction was successful
|
|
1941
|
+
* setTimeout(async () => {
|
|
1942
|
+
* const transaction = await programManager.networkClient.getTransaction(tx_id);
|
|
1943
|
+
* assert(transaction.id() === tx_id);
|
|
1944
|
+
* }, 10000);
|
|
1887
1945
|
*/
|
|
1888
1946
|
async split(splitAmount, amountRecord, privateKey, offlineQuery) {
|
|
1889
1947
|
// Get the private key from the account if it is not provided in the parameters
|
|
@@ -1954,26 +2012,32 @@ class ProgramManager {
|
|
|
1954
2012
|
* @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate'
|
|
1955
2013
|
* @param {number} fee The fee to pay for the transfer
|
|
1956
2014
|
* @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
|
|
2015
|
+
* @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee records for the transfer transaction
|
|
1959
2016
|
* @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer
|
|
1960
2017
|
* @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
|
|
1961
2018
|
* @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
|
|
1962
2019
|
* @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
|
|
1963
|
-
* @returns {Promise<
|
|
2020
|
+
* @returns {Promise<Transaction>} The transaction object
|
|
1964
2021
|
*
|
|
1965
2022
|
* @example
|
|
2023
|
+
* /// Import the mainnet version of the sdk.
|
|
2024
|
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
2025
|
+
*
|
|
1966
2026
|
* // Create a new NetworkClient, KeyProvider, and RecordProvider
|
|
1967
|
-
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
1968
2027
|
* const keyProvider = new AleoKeyProvider();
|
|
1969
2028
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
2029
|
+
* keyProvider.useCache = true;
|
|
1970
2030
|
*
|
|
1971
2031
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
1972
|
-
* const programName = "hello_hello.aleo";
|
|
1973
2032
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
1974
|
-
* await programManager.
|
|
1975
|
-
*
|
|
1976
|
-
*
|
|
2033
|
+
* const tx = await programManager.buildTransferTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "public", 0.2, false);
|
|
2034
|
+
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
2035
|
+
*
|
|
2036
|
+
* // Verify the transaction was successful
|
|
2037
|
+
* setTimeout(async () => {
|
|
2038
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
2039
|
+
* assert(transaction.id() === tx.id());
|
|
2040
|
+
* }, 10000);
|
|
1977
2041
|
*/
|
|
1978
2042
|
async buildTransferTransaction(amount, recipient, transferType, fee, privateFee, recordSearchParams, amountRecord, feeRecord, privateKey, offlineQuery) {
|
|
1979
2043
|
// Validate the transfer type
|
|
@@ -2023,16 +2087,30 @@ class ProgramManager {
|
|
|
2023
2087
|
*
|
|
2024
2088
|
* @param {number} amount The amount of credits to transfer
|
|
2025
2089
|
* @param {string} recipient The recipient of the transfer
|
|
2026
|
-
* @param {
|
|
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
|
|
2090
|
+
* @param {number} fee The fee to pay for the transfer records for the transfer transaction
|
|
2033
2091
|
* @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
|
|
2034
2092
|
* @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
|
|
2035
|
-
* @returns {Promise<
|
|
2093
|
+
* @returns {Promise<Transaction>} The transaction object
|
|
2094
|
+
*
|
|
2095
|
+
* @example
|
|
2096
|
+
* /// Import the mainnet version of the sdk.
|
|
2097
|
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
2098
|
+
*
|
|
2099
|
+
* // Create a new NetworkClient, KeyProvider, and RecordProvider
|
|
2100
|
+
* const keyProvider = new AleoKeyProvider();
|
|
2101
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
2102
|
+
* keyProvider.useCache = true;
|
|
2103
|
+
*
|
|
2104
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
2105
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
2106
|
+
* const tx = await programManager.buildTransferPublicTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0.2);
|
|
2107
|
+
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
2108
|
+
*
|
|
2109
|
+
* // Verify the transaction was successful
|
|
2110
|
+
* setTimeout(async () => {
|
|
2111
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
2112
|
+
* assert(transaction.id() === tx.id());
|
|
2113
|
+
* }, 10000);
|
|
2036
2114
|
*/
|
|
2037
2115
|
async buildTransferPublicTransaction(amount, recipient, fee, privateKey, offlineQuery) {
|
|
2038
2116
|
return this.buildTransferTransaction(amount, recipient, "public", fee, false, undefined, undefined, undefined, privateKey, offlineQuery);
|
|
@@ -2045,13 +2123,32 @@ class ProgramManager {
|
|
|
2045
2123
|
* @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate'
|
|
2046
2124
|
* @param {number} fee The fee to pay for the transfer
|
|
2047
2125
|
* @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
|
|
2126
|
+
* @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee records for the transfer transaction
|
|
2050
2127
|
* @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer
|
|
2051
2128
|
* @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
|
|
2052
2129
|
* @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
|
|
2053
2130
|
* @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
|
|
2054
|
-
* @returns {Promise<
|
|
2131
|
+
* @returns {Promise<Transaction>} The transaction object
|
|
2132
|
+
*
|
|
2133
|
+
* @example
|
|
2134
|
+
* /// Import the mainnet version of the sdk.
|
|
2135
|
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
2136
|
+
*
|
|
2137
|
+
* // Create a new NetworkClient, KeyProvider, and RecordProvider
|
|
2138
|
+
* const keyProvider = new AleoKeyProvider();
|
|
2139
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
2140
|
+
* keyProvider.useCache = true;
|
|
2141
|
+
*
|
|
2142
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
2143
|
+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
2144
|
+
* const tx = await programManager.buildTransferPublicAsSignerTransaction(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0.2);
|
|
2145
|
+
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
2146
|
+
*
|
|
2147
|
+
* // Verify the transaction was successful
|
|
2148
|
+
* setTimeout(async () => {
|
|
2149
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
2150
|
+
* assert(transaction.id() === tx.id());
|
|
2151
|
+
* }, 10000);
|
|
2055
2152
|
*/
|
|
2056
2153
|
async buildTransferPublicAsSignerTransaction(amount, recipient, fee, privateKey, offlineQuery) {
|
|
2057
2154
|
return this.buildTransferTransaction(amount, recipient, "public", fee, false, undefined, undefined, undefined, privateKey, offlineQuery);
|
|
@@ -2064,25 +2161,31 @@ class ProgramManager {
|
|
|
2064
2161
|
* @param {string} transferType The type of transfer to perform - options: 'private', 'privateToPublic', 'public', 'publicToPrivate'
|
|
2065
2162
|
* @param {number} fee The fee to pay for the transfer
|
|
2066
2163
|
* @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
|
|
2164
|
+
* @param {RecordSearchParams | undefined} recordSearchParams Optional parameters for finding the amount and fee records for the transfer transaction
|
|
2069
2165
|
* @param {RecordPlaintext | string} amountRecord Optional amount record to use for the transfer
|
|
2070
2166
|
* @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
|
|
2071
2167
|
* @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
|
|
2072
2168
|
* @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
|
|
2073
|
-
* @returns {Promise<string>} The transaction id
|
|
2169
|
+
* @returns {Promise<string>} The transaction id
|
|
2074
2170
|
*
|
|
2075
2171
|
* @example
|
|
2172
|
+
* /// Import the mainnet version of the sdk.
|
|
2173
|
+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
2174
|
+
*
|
|
2076
2175
|
* // Create a new NetworkClient, KeyProvider, and RecordProvider
|
|
2077
|
-
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
2078
2176
|
* const keyProvider = new AleoKeyProvider();
|
|
2079
2177
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
2178
|
+
* keyProvider.useCache = true;
|
|
2080
2179
|
*
|
|
2081
2180
|
* // Initialize a program manager with the key provider to automatically fetch keys for executions
|
|
2082
2181
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
2083
|
-
* await programManager.
|
|
2084
|
-
*
|
|
2085
|
-
*
|
|
2182
|
+
* const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "public", 0.2, false);
|
|
2183
|
+
*
|
|
2184
|
+
* // Verify the transaction was successful
|
|
2185
|
+
* setTimeout(async () => {
|
|
2186
|
+
* const transaction = await programManager.networkClient.getTransaction(tx_id);
|
|
2187
|
+
* assert(transaction.id() === tx_id);
|
|
2188
|
+
* }, 10000);
|
|
2086
2189
|
*/
|
|
2087
2190
|
async transfer(amount, recipient, transferType, fee, privateFee, recordSearchParams, amountRecord, feeRecord, privateKey, offlineQuery) {
|
|
2088
2191
|
const tx = await this.buildTransferTransaction(amount, recipient, transferType, fee, privateFee, recordSearchParams, amountRecord, feeRecord, privateKey, offlineQuery);
|
|
@@ -2091,7 +2194,16 @@ class ProgramManager {
|
|
|
2091
2194
|
/**
|
|
2092
2195
|
* Build transaction to bond credits to a validator for later submission to the Aleo Network
|
|
2093
2196
|
*
|
|
2197
|
+
* @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.
|
|
2198
|
+
* @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
|
|
2199
|
+
* @param {number} amount The amount of credits to bond
|
|
2200
|
+
* @param {Partial<ExecuteOptions>} options - Override default execution options.
|
|
2201
|
+
* @returns {Promise<Transaction>} The transaction object
|
|
2202
|
+
*
|
|
2094
2203
|
* @example
|
|
2204
|
+
* // Import the mainnet version of the sdk.
|
|
2205
|
+
* import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
2206
|
+
*
|
|
2095
2207
|
* // Create a keyProvider to handle key management
|
|
2096
2208
|
* const keyProvider = new AleoKeyProvider();
|
|
2097
2209
|
* keyProvider.useCache = true;
|
|
@@ -2102,20 +2214,15 @@ class ProgramManager {
|
|
|
2102
2214
|
*
|
|
2103
2215
|
* // Create the bonding transaction object for later submission
|
|
2104
2216
|
* const tx = await programManager.buildBondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
|
|
2105
|
-
* console.log(tx);
|
|
2106
2217
|
*
|
|
2107
2218
|
* // The transaction can be later submitted to the network using the network client.
|
|
2108
|
-
*
|
|
2109
|
-
*
|
|
2110
|
-
*
|
|
2111
|
-
*
|
|
2112
|
-
*
|
|
2113
|
-
*
|
|
2114
|
-
*
|
|
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.
|
|
2219
|
+
* await programManager.networkClient.submitTransaction(tx.toString());
|
|
2220
|
+
*
|
|
2221
|
+
* // Verify the transaction was successful
|
|
2222
|
+
* setTimeout(async () => {
|
|
2223
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
2224
|
+
* assert(transaction.id() === tx.id());
|
|
2225
|
+
* }, 10000);
|
|
2119
2226
|
*/
|
|
2120
2227
|
async buildBondPublicTransaction(validator_address, withdrawal_address, amount, options = {}) {
|
|
2121
2228
|
const scaledAmount = Math.trunc(amount * 1000000);
|
|
@@ -2138,27 +2245,31 @@ class ProgramManager {
|
|
|
2138
2245
|
/**
|
|
2139
2246
|
* Bond credits to validator.
|
|
2140
2247
|
*
|
|
2248
|
+
* @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.
|
|
2249
|
+
* @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
|
|
2250
|
+
* @param {number} amount The amount of credits to bond
|
|
2251
|
+
* @param {Options} options Options for the execution
|
|
2252
|
+
* @returns {Promise<string>} The transaction id
|
|
2253
|
+
*
|
|
2141
2254
|
* @example
|
|
2255
|
+
* // Import the mainnet version of the sdk.
|
|
2256
|
+
* import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
2257
|
+
*
|
|
2142
2258
|
* // Create a keyProvider to handle key management
|
|
2143
2259
|
* const keyProvider = new AleoKeyProvider();
|
|
2144
2260
|
* keyProvider.useCache = true;
|
|
2145
2261
|
*
|
|
2146
2262
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
2147
2263
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
|
|
2148
|
-
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
2149
2264
|
*
|
|
2150
2265
|
* // Create the bonding transaction
|
|
2151
|
-
*
|
|
2152
|
-
*
|
|
2153
|
-
*
|
|
2154
|
-
*
|
|
2155
|
-
*
|
|
2156
|
-
*
|
|
2157
|
-
*
|
|
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
|
|
2266
|
+
* tx_id = await programManager.bondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
|
|
2267
|
+
*
|
|
2268
|
+
* // Verify the transaction was successful
|
|
2269
|
+
* setTimeout(async () => {
|
|
2270
|
+
* const transaction = await programManager.networkClient.getTransaction(tx_id);
|
|
2271
|
+
* assert(transaction.id() === tx_id);
|
|
2272
|
+
* }, 10000);
|
|
2162
2273
|
*/
|
|
2163
2274
|
async bondPublic(validator_address, withdrawal_address, amount, options = {}) {
|
|
2164
2275
|
const tx = await this.buildBondPublicTransaction(validator_address, withdrawal_address, amount, options);
|
|
@@ -2167,7 +2278,17 @@ class ProgramManager {
|
|
|
2167
2278
|
/**
|
|
2168
2279
|
* Build a bond_validator transaction for later submission to the Aleo Network.
|
|
2169
2280
|
*
|
|
2281
|
+
* @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.
|
|
2282
|
+
* @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
|
|
2283
|
+
* @param {number} amount The amount of credits to bond. A minimum of 10000 credits is required to bond as a delegator.
|
|
2284
|
+
* @param {number} commission The commission rate for the validator (must be between 0 and 100 - an error will be thrown if it is not)
|
|
2285
|
+
* @param {Partial<ExecuteOptions>} options - Override default execution options.
|
|
2286
|
+
* @returns {Promise<Transaction>} The transaction object
|
|
2287
|
+
*
|
|
2170
2288
|
* @example
|
|
2289
|
+
* // Import the mainnet version of the sdk.
|
|
2290
|
+
* import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
2291
|
+
*
|
|
2171
2292
|
* // Create a keyProvider to handle key management
|
|
2172
2293
|
* const keyProvider = new AleoKeyProvider();
|
|
2173
2294
|
* keyProvider.useCache = true;
|
|
@@ -2178,21 +2299,15 @@ class ProgramManager {
|
|
|
2178
2299
|
*
|
|
2179
2300
|
* // Create the bond validator transaction object for later use.
|
|
2180
2301
|
* const tx = await programManager.buildBondValidatorTransaction("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
|
|
2181
|
-
* console.log(tx);
|
|
2182
2302
|
*
|
|
2183
2303
|
* // The transaction can later be submitted to the network using the network client.
|
|
2184
|
-
* const tx_id = await programManager.networkClient.submitTransaction(tx);
|
|
2185
|
-
*
|
|
2186
|
-
*
|
|
2187
|
-
*
|
|
2188
|
-
*
|
|
2189
|
-
*
|
|
2190
|
-
*
|
|
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.
|
|
2304
|
+
* const tx_id = await programManager.networkClient.submitTransaction(tx.toString());
|
|
2305
|
+
*
|
|
2306
|
+
* // Verify the transaction was successful
|
|
2307
|
+
* setTimeout(async () => {
|
|
2308
|
+
* const transaction = await programManager.networkClient.getTransaction(tx_id);
|
|
2309
|
+
* assert(transaction.id() === tx_id);
|
|
2310
|
+
* }, 10000);
|
|
2196
2311
|
*/
|
|
2197
2312
|
async buildBondValidatorTransaction(validator_address, withdrawal_address, amount, commission, options = {}) {
|
|
2198
2313
|
const scaledAmount = Math.trunc(amount * 1000000);
|
|
@@ -2216,7 +2331,17 @@ class ProgramManager {
|
|
|
2216
2331
|
/**
|
|
2217
2332
|
* Build transaction to bond a validator.
|
|
2218
2333
|
*
|
|
2334
|
+
* @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.
|
|
2335
|
+
* @param {string} withdrawal_address Address to withdraw the staked credits to when unbond_public is called.
|
|
2336
|
+
* @param {number} amount The amount of credits to bond
|
|
2337
|
+
* @param {number} commission The commission rate for the validator (must be between 0 and 100 - an error will be thrown if it is not)
|
|
2338
|
+
* @param {Partial<ExecuteOptions>} options - Override default execution options.
|
|
2339
|
+
* @returns {Promise<string>} The transaction id
|
|
2340
|
+
*
|
|
2219
2341
|
* @example
|
|
2342
|
+
* // Import the mainnet version of the sdk.
|
|
2343
|
+
* import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
2344
|
+
*
|
|
2220
2345
|
* // Create a keyProvider to handle key management
|
|
2221
2346
|
* const keyProvider = new AleoKeyProvider();
|
|
2222
2347
|
* keyProvider.useCache = true;
|
|
@@ -2228,23 +2353,18 @@ class ProgramManager {
|
|
|
2228
2353
|
* // Create the bonding transaction
|
|
2229
2354
|
* const tx_id = await programManager.bondValidator("aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
|
|
2230
2355
|
*
|
|
2231
|
-
*
|
|
2232
|
-
*
|
|
2233
|
-
*
|
|
2234
|
-
*
|
|
2235
|
-
*
|
|
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.
|
|
2356
|
+
* // Verify the transaction was successful
|
|
2357
|
+
* setTimeout(async () => {
|
|
2358
|
+
* const transaction = await programManager.networkClient.getTransaction(tx_id);
|
|
2359
|
+
* assert(transaction.id() === tx_id);
|
|
2360
|
+
* }, 10000);
|
|
2241
2361
|
*/
|
|
2242
2362
|
async bondValidator(validator_address, withdrawal_address, amount, commission, options = {}) {
|
|
2243
2363
|
const tx = await this.buildBondValidatorTransaction(validator_address, withdrawal_address, amount, commission, options);
|
|
2244
2364
|
return await this.networkClient.submitTransaction(tx);
|
|
2245
2365
|
}
|
|
2246
2366
|
/**
|
|
2247
|
-
* Build
|
|
2367
|
+
* Build an unbond_public execution transaction to unbond credits from a validator in the Aleo network.
|
|
2248
2368
|
*
|
|
2249
2369
|
* @param {string} staker_address - The address of the staker who is unbonding the credits.
|
|
2250
2370
|
* @param {number} amount - The amount of credits to unbond (scaled by 1,000,000).
|
|
@@ -2252,6 +2372,9 @@ class ProgramManager {
|
|
|
2252
2372
|
* @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error message.
|
|
2253
2373
|
*
|
|
2254
2374
|
* @example
|
|
2375
|
+
* // Import the mainnet version of the sdk.
|
|
2376
|
+
* import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
2377
|
+
*
|
|
2255
2378
|
* // Create a keyProvider to handle key management.
|
|
2256
2379
|
* const keyProvider = new AleoKeyProvider();
|
|
2257
2380
|
* keyProvider.useCache = true;
|
|
@@ -2259,10 +2382,15 @@ class ProgramManager {
|
|
|
2259
2382
|
* // Create a new ProgramManager with the key that will be used to unbond credits.
|
|
2260
2383
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
|
|
2261
2384
|
* const tx = await programManager.buildUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 2000000);
|
|
2262
|
-
* console.log(tx);
|
|
2263
2385
|
*
|
|
2264
2386
|
* // The transaction can be submitted later to the network using the network client.
|
|
2265
|
-
* programManager.networkClient.submitTransaction(tx);
|
|
2387
|
+
* programManager.networkClient.submitTransaction(tx.toString());
|
|
2388
|
+
*
|
|
2389
|
+
* // Verify the transaction was successful
|
|
2390
|
+
* setTimeout(async () => {
|
|
2391
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
2392
|
+
* assert(transaction.id() === tx.id());
|
|
2393
|
+
* }, 10000);
|
|
2266
2394
|
*/
|
|
2267
2395
|
async buildUnbondPublicTransaction(staker_address, amount, options = {}) {
|
|
2268
2396
|
const scaledAmount = Math.trunc(amount * 1000000);
|
|
@@ -2283,9 +2411,22 @@ class ProgramManager {
|
|
|
2283
2411
|
return this.buildExecutionTransaction(executeOptions);
|
|
2284
2412
|
}
|
|
2285
2413
|
/**
|
|
2286
|
-
* Unbond a specified amount of staked credits.
|
|
2414
|
+
* Unbond a specified amount of staked credits. If the address of the executor of this function is an existing
|
|
2415
|
+
* validator, it will subtract this amount of credits from the validator's staked credits. If there are less than
|
|
2416
|
+
* 1,000,000 credits staked pool after the unbond, the validator will be removed from the validator set. If the
|
|
2417
|
+
* address of the executor of this function is not a validator and has credits bonded as a delegator, it will
|
|
2418
|
+
* subtract this amount of credits from the delegator's staked credits. If there are less than 10 credits bonded
|
|
2419
|
+
* after the unbond operation, the delegator will be removed from the validator's staking pool.
|
|
2420
|
+
*
|
|
2421
|
+
* @param {string} staker_address Address of the staker who is unbonding the credits
|
|
2422
|
+
* @param {number} amount Amount of credits to unbond.
|
|
2423
|
+
* @param {ExecuteOptions} options Options for the execution
|
|
2424
|
+
* @returns {Promise<string>} The transaction id
|
|
2287
2425
|
*
|
|
2288
2426
|
* @example
|
|
2427
|
+
* // Import the mainnet version of the sdk.
|
|
2428
|
+
* import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
2429
|
+
*
|
|
2289
2430
|
* // Create a keyProvider to handle key management
|
|
2290
2431
|
* const keyProvider = new AleoKeyProvider();
|
|
2291
2432
|
* keyProvider.useCache = true;
|
|
@@ -2294,18 +2435,14 @@ class ProgramManager {
|
|
|
2294
2435
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
|
|
2295
2436
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
2296
2437
|
*
|
|
2297
|
-
* // Create the
|
|
2438
|
+
* // Create the unbond_public transaction and send it to the network
|
|
2298
2439
|
* const tx_id = await programManager.unbondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 10);
|
|
2299
2440
|
*
|
|
2300
|
-
*
|
|
2301
|
-
*
|
|
2302
|
-
*
|
|
2303
|
-
*
|
|
2304
|
-
*
|
|
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
|
|
2441
|
+
* // Verify the transaction was successful
|
|
2442
|
+
* setTimeout(async () => {
|
|
2443
|
+
* const transaction = await programManager.networkClient.getTransaction(tx_id);
|
|
2444
|
+
* assert(transaction.id() === tx_id);
|
|
2445
|
+
* }, 10000);
|
|
2309
2446
|
*/
|
|
2310
2447
|
async unbondPublic(staker_address, amount, options = {}) {
|
|
2311
2448
|
const tx = await this.buildUnbondPublicTransaction(staker_address, amount, options);
|
|
@@ -2319,6 +2456,9 @@ class ProgramManager {
|
|
|
2319
2456
|
* @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error message.
|
|
2320
2457
|
*
|
|
2321
2458
|
* @example
|
|
2459
|
+
* // Import the mainnet version of the sdk.
|
|
2460
|
+
* import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
2461
|
+
*
|
|
2322
2462
|
* // Create a keyProvider to handle key management
|
|
2323
2463
|
* const keyProvider = new AleoKeyProvider();
|
|
2324
2464
|
* keyProvider.useCache = true;
|
|
@@ -2326,12 +2466,17 @@ class ProgramManager {
|
|
|
2326
2466
|
* // Create a new ProgramManager with the key that will be used to claim unbonded credits.
|
|
2327
2467
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
|
|
2328
2468
|
*
|
|
2329
|
-
* // Create the
|
|
2469
|
+
* // Create the claim_unbond_public transaction object for later use.
|
|
2330
2470
|
* const tx = await programManager.buildClaimUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j");
|
|
2331
|
-
* console.log(tx);
|
|
2332
2471
|
*
|
|
2333
2472
|
* // The transaction can be submitted later to the network using the network client.
|
|
2334
|
-
* programManager.networkClient.submitTransaction(tx);
|
|
2473
|
+
* programManager.networkClient.submitTransaction(tx.toString());
|
|
2474
|
+
*
|
|
2475
|
+
* // Verify the transaction was successful
|
|
2476
|
+
* setTimeout(async () => {
|
|
2477
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
2478
|
+
* assert(transaction.id() === tx.id());
|
|
2479
|
+
* }, 10000);
|
|
2335
2480
|
*/
|
|
2336
2481
|
async buildClaimUnbondPublicTransaction(staker_address, options = {}) {
|
|
2337
2482
|
const { programName = "credits.aleo", functionName = "claim_unbond_public", fee = options.fee || 2, privateFee = false, inputs = [staker_address], keySearchParams = new AleoKeyProviderParams({
|
|
@@ -2354,7 +2499,14 @@ class ProgramManager {
|
|
|
2354
2499
|
* Claim unbonded credits. If credits have been unbonded by the account executing this function, this method will
|
|
2355
2500
|
* claim them and add them to the public balance of the account.
|
|
2356
2501
|
*
|
|
2502
|
+
* @param {string} staker_address Address of the staker who is claiming the credits
|
|
2503
|
+
* @param {ExecuteOptions} options
|
|
2504
|
+
* @returns {Promise<string>} The transaction id
|
|
2505
|
+
*
|
|
2357
2506
|
* @example
|
|
2507
|
+
* // Import the mainnet version of the sdk.
|
|
2508
|
+
* import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
2509
|
+
*
|
|
2358
2510
|
* // Create a keyProvider to handle key management
|
|
2359
2511
|
* const keyProvider = new AleoKeyProvider();
|
|
2360
2512
|
* keyProvider.useCache = true;
|
|
@@ -2363,12 +2515,14 @@ class ProgramManager {
|
|
|
2363
2515
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
|
|
2364
2516
|
* programManager.setAccount(new Account("YourPrivateKey"));
|
|
2365
2517
|
*
|
|
2366
|
-
* // Create the
|
|
2518
|
+
* // Create the claim_unbond_public transaction
|
|
2367
2519
|
* const tx_id = await programManager.claimUnbondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j");
|
|
2368
2520
|
*
|
|
2369
|
-
*
|
|
2370
|
-
*
|
|
2371
|
-
*
|
|
2521
|
+
* // Verify the transaction was successful
|
|
2522
|
+
* setTimeout(async () => {
|
|
2523
|
+
* const transaction = await programManager.networkClient.getTransaction(tx_id);
|
|
2524
|
+
* assert(transaction.id() === tx_id);
|
|
2525
|
+
* }, 10000);
|
|
2372
2526
|
*/
|
|
2373
2527
|
async claimUnbondPublic(staker_address, options = {}) {
|
|
2374
2528
|
const tx = await this.buildClaimUnbondPublicTransaction(staker_address, options);
|
|
@@ -2385,24 +2539,32 @@ class ProgramManager {
|
|
|
2385
2539
|
* 1. Allow a validator to leave the committee, by closing themselves to stakers and then unbonding all of their stakers.
|
|
2386
2540
|
* 2. Allow a validator to maintain their % of stake, by closing themselves to allowing more stakers to bond to them.
|
|
2387
2541
|
*
|
|
2542
|
+
* @param {boolean} validator_state
|
|
2543
|
+
* @param {Partial<ExecuteOptions>} options - Override default execution options
|
|
2544
|
+
* @returns {Promise<Transaction>} The transaction object
|
|
2545
|
+
*
|
|
2388
2546
|
* @example
|
|
2547
|
+
* // Import the mainnet version of the sdk.
|
|
2548
|
+
* import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
2549
|
+
*
|
|
2389
2550
|
* // Create a keyProvider to handle key management
|
|
2390
2551
|
* const keyProvider = new AleoKeyProvider();
|
|
2391
2552
|
* keyProvider.useCache = true;
|
|
2392
2553
|
*
|
|
2393
2554
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
2394
2555
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
|
|
2395
|
-
* programManager.setAccount(new Account("ValidatorPrivateKey"));
|
|
2396
2556
|
*
|
|
2397
|
-
* // Create the
|
|
2557
|
+
* // Create the set_validator_state transaction
|
|
2398
2558
|
* const tx = await programManager.buildSetValidatorStateTransaction(true);
|
|
2399
2559
|
*
|
|
2400
2560
|
* // The transaction can be submitted later to the network using the network client.
|
|
2401
|
-
* programManager.networkClient.submitTransaction(tx);
|
|
2561
|
+
* programManager.networkClient.submitTransaction(tx.toString());
|
|
2402
2562
|
*
|
|
2403
|
-
*
|
|
2404
|
-
*
|
|
2405
|
-
*
|
|
2563
|
+
* // Verify the transaction was successful
|
|
2564
|
+
* setTimeout(async () => {
|
|
2565
|
+
* const transaction = await programManager.networkClient.getTransaction(tx.id());
|
|
2566
|
+
* assert(transaction.id() === tx.id());
|
|
2567
|
+
* }, 10000);
|
|
2406
2568
|
*/
|
|
2407
2569
|
async buildSetValidatorStateTransaction(validator_state, options = {}) {
|
|
2408
2570
|
const { programName = "credits.aleo", functionName = "set_validator_state", fee = 1, privateFee = false, inputs = [validator_state.toString()], keySearchParams = new AleoKeyProviderParams({
|
|
@@ -2432,21 +2594,29 @@ class ProgramManager {
|
|
|
2432
2594
|
* 1. Allow a validator to leave the committee, by closing themselves to stakers and then unbonding all of their stakers.
|
|
2433
2595
|
* 2. Allow a validator to maintain their % of stake, by closing themselves to allowing more stakers to bond to them.
|
|
2434
2596
|
*
|
|
2597
|
+
* @param {boolean} validator_state
|
|
2598
|
+
* @param {Partial<ExecuteOptions>} options - Override default execution options
|
|
2599
|
+
* @returns {Promise<string>} The transaction id
|
|
2600
|
+
*
|
|
2435
2601
|
* @example
|
|
2602
|
+
* // Import the mainnet version of the sdk.
|
|
2603
|
+
* import { AleoKeyProvider, ProgramManager } from "@provablehq/sdk/mainnet.js";
|
|
2604
|
+
*
|
|
2436
2605
|
* // Create a keyProvider to handle key management
|
|
2437
2606
|
* const keyProvider = new AleoKeyProvider();
|
|
2438
2607
|
* keyProvider.useCache = true;
|
|
2439
2608
|
*
|
|
2440
2609
|
* // Create a new ProgramManager with the key that will be used to bond credits
|
|
2441
2610
|
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
|
|
2442
|
-
* programManager.setAccount(new Account("ValidatorPrivateKey"));
|
|
2443
2611
|
*
|
|
2444
|
-
* // Create the
|
|
2612
|
+
* // Create the set_validator_state transaction
|
|
2445
2613
|
* const tx_id = await programManager.setValidatorState(true);
|
|
2446
2614
|
*
|
|
2447
|
-
*
|
|
2448
|
-
*
|
|
2449
|
-
*
|
|
2615
|
+
* // Verify the transaction was successful
|
|
2616
|
+
* setTimeout(async () => {
|
|
2617
|
+
* const transaction = await programManager.networkClient.getTransaction(tx_id);
|
|
2618
|
+
* assert(transaction.id() === tx_id);
|
|
2619
|
+
* }, 10000);
|
|
2450
2620
|
*/
|
|
2451
2621
|
async setValidatorState(validator_state, options = {}) {
|
|
2452
2622
|
const tx = await this.buildSetValidatorStateTransaction(validator_state, options);
|
|
@@ -2529,4 +2699,4 @@ function validateTransferType(transferType) {
|
|
|
2529
2699
|
}
|
|
2530
2700
|
|
|
2531
2701
|
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-
|
|
2702
|
+
//# sourceMappingURL=program-manager-D0WpABBc.js.map
|