Skip to content

Commit be6b95c

Browse files
committed
Fixing examples
1 parent 5c021e5 commit be6b95c

File tree

15 files changed

+234
-155
lines changed

15 files changed

+234
-155
lines changed

create-leo-app/template-node-ts/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
5050
functionName: aleoFunction,
5151
inputs,
5252
proveExecution: true,
53-
keyProviderParams,
53+
keySearchParams: keyProviderParams,
5454
});
5555
console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());
5656

create-leo-app/template-node/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
4444
functionName: aleoFunction,
4545
inputs,
4646
proveExecution: true,
47-
keyProviderParams,
47+
keySearchParams: keyProviderParams,
4848
});
4949
console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());
5050

create-leo-app/template-offline-public-transaction-ts/src/index.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function buildTransferPublicTxOffline(recipientAddress: Address, amount: n
1919
const transferPublicProvingKey = ProvingKey.fromBytes(
2020
await getLocalKey(<string>keyPaths[CREDITS_PROGRAM_KEYS.transfer_public.locator])
2121
);
22-
22+
2323
// Create an offline key provider
2424
console.log("Creating offline key provider");
2525
const offlineKeyProvider = new OfflineKeyProvider();
@@ -53,21 +53,20 @@ try {
5353

5454
// Build tne transfer_public transaction offline
5555
console.log("Building transfer transaction offline");
56-
return programManager.buildTransferPublicAsSignerTransaction(
56+
return programManager.buildTransferPublicAsSignerTransaction({
5757
amount,
58-
recipientAddress.to_string(),
59-
0.28,
60-
undefined,
58+
recipient: recipientAddress.to_string(),
59+
priorityFee: 0.28,
6160
offlineQuery,
62-
);
61+
});
6362
}
6463

6564
/// Build bonding and unbonding transactions without connection to the internet
6665
async function buildBondingTxOffline(
67-
validatorAddress: Address,
68-
withdrawalAddress: Address,
69-
amount: number,
70-
latestStateRoot: string,
66+
validatorAddress: Address,
67+
withdrawalAddress: Address,
68+
amount: number,
69+
latestStateRoot: string,
7170
keyPaths: {}
7271
): Promise<Transaction[]> {
7372
// Create an offline program manager
@@ -115,12 +114,12 @@ async function buildBondingTxOffline(
115114
};
116115

117116

118-
const bondTx = <Transaction>await programManager.buildBondPublicTransaction(
119-
validatorAddress.to_string(),
120-
withdrawalAddress.to_string(),
117+
const bondTx = <Transaction>await programManager.buildBondPublicTransaction({
118+
validatorAddress: validatorAddress.to_string(),
119+
withdrawalAddress: withdrawalAddress.to_string(),
121120
amount,
122-
bondPublicOptions
123-
);
121+
options: bondPublicOptions
122+
});
124123

125124
console.log("\nbond_public transaction built!\n");
126125

@@ -129,11 +128,11 @@ async function buildBondingTxOffline(
129128
offlineQuery: new OfflineQuery(0, latestStateRoot)
130129
};
131130

132-
const unBondTx = <Transaction>await programManager.buildUnbondPublicTransaction(
133-
stakerAddress.to_string(),
131+
const unBondTx = <Transaction>await programManager.buildUnbondPublicTransaction({
132+
stakerAddress: stakerAddress.to_string(),
134133
amount,
135-
unbondPublicOptions
136-
);
134+
options: unbondPublicOptions,
135+
});
137136
console.log("\nunbond_public transaction built!\n");
138137

139138
console.log("Building a claim_unbond_public transaction offline");
@@ -142,10 +141,10 @@ async function buildBondingTxOffline(
142141
offlineQuery: new OfflineQuery(0, latestStateRoot)
143142
};
144143

145-
const claimUnbondTx = <Transaction>await programManager.buildClaimUnbondPublicTransaction(
146-
stakerAddress.to_string(),
147-
claimUnbondPublicOptions
148-
);
144+
const claimUnbondTx = <Transaction>await programManager.buildClaimUnbondPublicTransaction({
145+
stakerAddress: stakerAddress.to_string(),
146+
options: claimUnbondPublicOptions,
147+
});
149148
console.log("\nclaim_unbond_public transaction built!\n");
150149
return [bondTx, unBondTx, claimUnbondTx];
151150
}
@@ -188,4 +187,4 @@ console.log(`---------------------------------------------------------`);
188187
// ONLINE COMPONENT (Uncomment this part to send the transaction to the Aleo Network on an internet connected machine)
189188
// Submit the transaction to the network
190189
// const transferTxId = await networkClient.submitTransaction(transferTx);
191-
//---------------------------------------------------------
190+
//---------------------------------------------------------

create-leo-app/template-react-leo/src/workers/worker.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ async function deployProgram(program) {
4747
const recordProvider = new NetworkRecordProvider(account, networkClient);
4848

4949
// Initialize a program manager to talk to the Aleo network with the configured key and record providers
50-
const programManager = new ProgramManager(
51-
"https://api.explorer.provable.com/v1",
50+
const programManager = new ProgramManager({
51+
host: "https://api.explorer.provable.com/v1",
5252
keyProvider,
5353
recordProvider,
54-
);
54+
});
5555

5656
programManager.setAccount(account);
5757

5858
// Define a fee to pay to deploy the program
5959
const fee = 1.9; // 1.9 Aleo credits
6060

6161
// Deploy the program to the Aleo network
62-
const tx_id = await programManager.deploy(program, fee);
62+
const tx_id = await programManager.deploy({ program, priorityFee: fee });
6363

6464
// Optional: Pass in fee record manually to avoid long scan times
6565
// const feeRecord = "{ owner: aleo1xxx...xxx.private, microcredits: 2000000u64.private, _nonce: 123...789group.public}";
66-
// const tx_id = await programManager.deploy(program, fee, undefined, feeRecord);
66+
// const tx_id = await programManager.deploy({ program, priorityFee: fee, feeRecord });
6767

6868
return tx_id;
6969
}

create-leo-app/template-react-managed-worker/src/App.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ function App() {
2727
" output r2 as u32.private;\n";
2828

2929
setLoading(true);
30-
const result = await aleoWorker.run(hello_hello_program,"hello", ["5u32", "5u32"], "APrivateKey1zkp778oUFSck3PZA5xppgp4trFwkkD6xnUXtxcBCfsq4URJ")
30+
const result = await aleoWorker.run({
31+
program: hello_hello_program,
32+
functionName: "hello",
33+
inputs: ["5u32", "5u32"],
34+
privateKey: "APrivateKey1zkp778oUFSck3PZA5xppgp4trFwkkD6xnUXtxcBCfsq4URJ",
35+
});
3136
setLoading(false);
3237

3338
alert(JSON.stringify(result));

create-leo-app/template-react-ts/src/workers/worker.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ async function localProgramExecution(program, aleoFunction, inputs) {
1919
const account = new Account();
2020
programManager.setAccount(account);
2121

22-
const executionResponse = await programManager.run(
22+
const executionResponse = await programManager.run({
2323
program,
24-
aleoFunction,
24+
functionName: aleoFunction,
2525
inputs,
26-
false,
27-
);
26+
proveExecution: false,
27+
});
2828
return executionResponse.getOutputs();
2929
}
3030

@@ -48,23 +48,23 @@ async function deployProgram(program) {
4848
const recordProvider = new NetworkRecordProvider(account, networkClient);
4949

5050
// Initialize a program manager to talk to the Aleo network with the configured key and record providers
51-
const programManager = new ProgramManager(
52-
"https://api.explorer.provable.com/v1",
51+
const programManager = new ProgramManager({
52+
host: "https://api.explorer.provable.com/v1",
5353
keyProvider,
5454
recordProvider,
55-
);
55+
});
5656

5757
programManager.setAccount(account);
5858

5959
// Define a fee to pay to deploy the program
6060
const fee = 1.9; // 1.9 Aleo credits
6161

6262
// Deploy the program to the Aleo network
63-
const tx_id = await programManager.deploy(program, fee);
63+
const tx_id = await programManager.deploy({ program, priorityFee: fee });
6464

6565
// Optional: Pass in fee record manually to avoid long scan times
6666
// const feeRecord = "{ owner: aleo1xxx...xxx.private, microcredits: 2000000u64.private, _nonce: 123...789group.public}";
67-
// const tx_id = await programManager.deploy(program, fee, undefined, feeRecord);
67+
// const tx_id = await programManager.deploy({ program, priorityFee: fee, feeRecord });
6868

6969
return tx_id;
7070
}

create-leo-app/template-vanilla/worker.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ async function deployProgram(program) {
5555
const recordProvider = new NetworkRecordProvider(account, networkClient);
5656

5757
// Initialize a program manager to talk to the Aleo network with the configured key and record providers
58-
const programManager = new ProgramManager(
59-
"https://api.explorer.provable.com/v1",
58+
const programManager = new ProgramManager({
59+
host: "https://api.explorer.provable.com/v1",
6060
keyProvider,
6161
recordProvider,
62-
);
62+
});
6363

6464
programManager.setAccount(account);
6565

6666
// Define a fee to pay to deploy the program
6767
const fee = 1.9; // 1.9 Aleo credits
6868

6969
// Deploy the program to the Aleo network
70-
const tx_id = await programManager.deploy(program, fee);
70+
const tx_id = await programManager.deploy({ program, priorityFee: fee });
7171

7272
// Optional: Pass in fee record manually to avoid long scan times
7373
// const feeRecord = "{ owner: aleo1xxx...xxx.private, microcredits: 2000000u64.private, _nonce: 123...789group.public}";
74-
// const tx_id = await programManager.deploy(program, fee, undefined, feeRecord);
74+
// const tx_id = await programManager.deploy({ program, priorityFee: fee, feeRecord });
7575

7676
return tx_id;
7777
}

sdk/e2e/mainnet/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
4545
functionName: aleoFunction,
4646
inputs,
4747
proveExecution: true,
48-
keyProviderParams,
48+
keySearchParams: keyProviderParams,
4949
});
5050
console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());
5151

sdk/e2e/testnet/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
4444
functionName: aleoFunction,
4545
inputs,
4646
proveExecution: true,
47-
keyProviderParams,
47+
keySearchParams: keyProviderParams,
4848
});
4949
console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());
5050

sdk/src/function-key-provider.ts

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,13 @@ interface FunctionKeyProvider {
150150
* const recordProvider = new NetworkRecordProvider(account, networkClient);
151151
*
152152
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
153-
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
154-
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
153+
* const programManager = new ProgramManager({ host: "https://api.explorer.provable.com/v1", keyProvider, recordProvider });
154+
* programManager.transfer({
155+
* amount: 1,
156+
* recipient: "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at",
157+
* transferType: "public",
158+
* priorityFee: 0.5,
159+
* });
155160
*
156161
* // Keys can also be fetched manually
157162
* const searchParams = new IndexDbSearch({db: "keys", keyId: "credits.aleo:transferPrivate"});
@@ -200,8 +205,13 @@ interface FunctionKeyProvider {
200205
* const recordProvider = new NetworkRecordProvider(account, networkClient);
201206
*
202207
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
203-
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
204-
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
208+
* const programManager = new ProgramManager({ host: "https://api.explorer.provable.com/v1", keyProvider, recordProvider });
209+
* programManager.transfer({
210+
* amount: 1,
211+
* recipient: "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at",
212+
* transferType: "public",
213+
* priorityFee: 0.5,
214+
* });
205215
*
206216
* // Keys can also be fetched manually
207217
* const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
@@ -323,8 +333,13 @@ class AleoKeyProvider implements FunctionKeyProvider {
323333
* const recordProvider = new NetworkRecordProvider(account, networkClient);
324334
*
325335
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
326-
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
327-
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
336+
* const programManager = new ProgramManager({ host: "https://api.explorer.provable.com/v1", keyProvider, recordProvider });
337+
* programManager.transfer({
338+
* amount: 1,
339+
* recipient: "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at",
340+
* transferType: "public",
341+
* priorityFee: 0.5,
342+
* });
328343
*
329344
* // Keys can also be fetched manually using the key provider
330345
* const keySearchParams = { "cacheKey": "myProgram:myFunction" };
@@ -380,8 +395,13 @@ class AleoKeyProvider implements FunctionKeyProvider {
380395
* const recordProvider = new NetworkRecordProvider(account, networkClient);
381396
*
382397
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
383-
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
384-
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
398+
* const programManager = new ProgramManager({ host: "https://api.explorer.provable.com/v1", keyProvider, recordProvider });
399+
* programManager.transfer({
400+
* amount: 1,
401+
* recipient: "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at",
402+
* transferType: "public",
403+
* priorityFee: 0.5,
404+
* });
385405
*
386406
* // Keys can also be fetched manually
387407
* const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.fetchRemoteKeys({
@@ -506,8 +526,13 @@ class AleoKeyProvider implements FunctionKeyProvider {
506526
* const recordProvider = new NetworkRecordProvider(account, networkClient);
507527
*
508528
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
509-
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
510-
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
529+
* const programManager = new ProgramManager({ host: "https://api.explorer.provable.com/v1", keyProvider, recordProvider });
530+
* programManager.transfer({
531+
* amount: 1,
532+
* recipient: "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at",
533+
* transferType: "public",
534+
* priorityFee: 0.5,
535+
* });
511536
*
512537
* // Keys can also be fetched manually
513538
* const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");

0 commit comments

Comments
 (0)