Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions create-leo-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"devDependencies": {
"@types/minimist": "^1.2.5",
"@types/node": "^24.1.0",
"@types/prompts": "^2.4.9",
"kolorist": "^1.8.0",
"minimist": "^1.2.8",
Expand Down
8 changes: 4 additions & 4 deletions create-leo-app/template-extension/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ async function localProgramExecution(program, aleoFunction, inputs) {
const account = new Account();
programManager.setAccount(account);

const executionResponse = await programManager.run(
const executionResponse = await programManager.run({
program,
aleoFunction,
functionName: aleoFunction,
inputs,
false,
);
proveExecution: false,
});
return executionResponse.getOutputs();
}

Expand Down
3 changes: 2 additions & 1 deletion create-leo-app/template-nextjs-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@types/node": "^22.12.0",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"typescript": "^5.7.3"
"typescript": "^5.7.3",
"webpack": "^5.101.0"
}
}
8 changes: 4 additions & 4 deletions create-leo-app/template-nextjs-ts/src/app/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ async function localProgramExecution(program: string, aleoFunction: string, inpu
const account = new Account();
programManager.setAccount(account);

const executionResponse = await programManager.run(
const executionResponse = await programManager.run({
program,
aleoFunction,
functionName: aleoFunction,
inputs,
false,
);
proveExecution: false,
});
return executionResponse.getOutputs();
}

Expand Down
19 changes: 11 additions & 8 deletions create-leo-app/template-node-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)

// Pre-synthesize the program keys and then cache them in memory using key provider
try {
const keyPair = await programManager.synthesizeKeys(hello_hello_program, aleoFunction, inputs);
const keyPair = await programManager.synthesizeKeys({
program: hello_hello_program,
functionName: aleoFunction,
inputs,
});

programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);

Expand All @@ -41,18 +45,17 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)

// Execute once using the key provider params defined above. This will use the cached proving keys and make
// execution significantly faster.
let executionResponse = await programManager.run(
let executionResponse = await programManager.run({
program,
aleoFunction,
functionName: aleoFunction,
inputs,
true,
undefined,
keyProviderParams,
);
proveExecution: true,
keySearchParams: keyProviderParams,
});
console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());

// Verify the execution using the verifying key that was generated earlier.
if (programManager.verifyExecution(executionResponse, 9_000_000)) {
if (programManager.verifyExecution({ executionResponse, blockHeight: 9_000_000 })) {
console.log("hello_hello/hello execution verified!");
} else {
throw("Execution failed verification!");
Expand Down
19 changes: 11 additions & 8 deletions create-leo-app/template-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ async function localProgramExecution(program, programName, functionName, inputs)

// Pre-synthesize the program keys and then cache them in memory using key provider.
console.log("Synthesizing hello_hello/hello keys");
const keyPair = await programManager.synthesizeKeys(hello_hello_program, functionName, inputs);
const keyPair = await programManager.synthesizeKeys({
program: hello_hello_program,
functionName,
inputs,
});
programManager.keyProvider.cacheKeys(`${programName}:${functionName}`, keyPair);

// Specify parameters for the key provider to use search for program keys. In particular specify the cache key
Expand All @@ -39,18 +43,17 @@ async function localProgramExecution(program, programName, functionName, inputs)
// Execute once using the key provider params defined above. This will use the cached proving keys and make
// execution significantly faster.
console.log("Executing hello_hello/hello");
let executionResponse = await programManager.run(
let executionResponse = await programManager.run({
program,
functionName,
inputs,
true,
undefined,
keyProviderParams,
);
proveExecution: true,
keySearchParams: keyProviderParams,
});
console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());

// Verify the execution using the verifying key that was generated earlier.
if (programManager.verifyExecution(executionResponse, 9_000_000)) {
if (programManager.verifyExecution({ executionResponse, blockHeight: 9_000_000 })) {
console.log("hello_hello/hello execution verified!");
} else {
throw("Execution failed verification!");
Expand Down Expand Up @@ -86,4 +89,4 @@ async function remoteProgramExecution(programName, functionName, inputs) {
// console.log("Starting remote execute");
// const auctionTicket = "{\n owner: aleo12a4wll9ax6w5355jph0dr5wt2vla5sss2t4cnch0tc3vzh643v8qcfvc7a.private,\n auction: {\n starting_bid: 1000u64.private,\n name: 35399035103896773146887283777field.private,\n item: {\n id: 2711777270856651361584090827715149911900945757872672230578290769243507539617field.private,\n offchain_data: [\n 988474637487226873250021955104421895943605632761729320744454284792013483886field.private,\n 1018595503607749325560812785092303652308909717269501712857428145700763090203field.private,\n 1866354748676879328546224733327549476838379876255164483333908854380501015560field.private,\n 17649382157field.private\n ]\n }\n },\n auction_id: 4494702806735512695876583707511065751304542460719196393147692059573188109243field.private,\n settings: {\n auction_privacy: 1field.private,\n bid_types_accepted: 2field.private\n },\n _nonce: 3369967065799891136255379173673996324404175734426175774361522329924029135340group.public,\n _version: 0u8.public\n}";
// const privateBid = "{\n owner: aleo12a4wll9ax6w5355jph0dr5wt2vla5sss2t4cnch0tc3vzh643v8qcfvc7a.private,\n bid: {\n amount: 50000u64.private,\n auction_id: 4494702806735512695876583707511065751304542460719196393147692059573188109243field.private,\n bid_public_key: 7957235921075215080384898776027711008106448988910535634014947882222019778701group.private\n },\n bid_id: 7560059211950188901208146469854635725646381155467709838136796808753178551929field.private,\n _nonce: 6603986437928263590097393830337419611438422585243442121397081002092267314422group.public,\n _version: 0u8.public\n}";
// await remoteProgramExecution("private_auction_test_3.aleo", "select_winner_private", [auctionTicket, privateBid]);
// await remoteProgramExecution("private_auction_test_3.aleo", "select_winner_private", [auctionTicket, privateBid]);
47 changes: 23 additions & 24 deletions create-leo-app/template-offline-public-transaction-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function buildTransferPublicTxOffline(recipientAddress: Address, amount: n
const transferPublicProvingKey = ProvingKey.fromBytes(
await getLocalKey(<string>keyPaths[CREDITS_PROGRAM_KEYS.transfer_public.locator])
);

// Create an offline key provider
console.log("Creating offline key provider");
const offlineKeyProvider = new OfflineKeyProvider();
Expand Down Expand Up @@ -53,21 +53,20 @@ try {

// Build tne transfer_public transaction offline
console.log("Building transfer transaction offline");
return programManager.buildTransferPublicAsSignerTransaction(
return programManager.buildTransferPublicAsSignerTransaction({
amount,
recipientAddress.to_string(),
0.28,
undefined,
recipient: recipientAddress.to_string(),
priorityFee: 0.28,
offlineQuery,
);
});
}

/// Build bonding and unbonding transactions without connection to the internet
async function buildBondingTxOffline(
validatorAddress: Address,
withdrawalAddress: Address,
amount: number,
latestStateRoot: string,
validatorAddress: Address,
withdrawalAddress: Address,
amount: number,
latestStateRoot: string,
keyPaths: {}
): Promise<Transaction[]> {
// Create an offline program manager
Expand Down Expand Up @@ -115,12 +114,12 @@ async function buildBondingTxOffline(
};


const bondTx = <Transaction>await programManager.buildBondPublicTransaction(
validatorAddress.to_string(),
withdrawalAddress.to_string(),
const bondTx = <Transaction>await programManager.buildBondPublicTransaction({
validatorAddress: validatorAddress.to_string(),
withdrawalAddress: withdrawalAddress.to_string(),
amount,
bondPublicOptions
);
options: bondPublicOptions
});

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

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

const unBondTx = <Transaction>await programManager.buildUnbondPublicTransaction(
stakerAddress.to_string(),
const unBondTx = <Transaction>await programManager.buildUnbondPublicTransaction({
stakerAddress: stakerAddress.to_string(),
amount,
unbondPublicOptions
);
options: unbondPublicOptions,
});
console.log("\nunbond_public transaction built!\n");

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

const claimUnbondTx = <Transaction>await programManager.buildClaimUnbondPublicTransaction(
stakerAddress.to_string(),
claimUnbondPublicOptions
);
const claimUnbondTx = <Transaction>await programManager.buildClaimUnbondPublicTransaction({
stakerAddress: stakerAddress.to_string(),
options: claimUnbondPublicOptions,
});
console.log("\nclaim_unbond_public transaction built!\n");
return [bondTx, unBondTx, claimUnbondTx];
}
Expand Down Expand Up @@ -188,4 +187,4 @@ console.log(`---------------------------------------------------------`);
// ONLINE COMPONENT (Uncomment this part to send the transaction to the Aleo Network on an internet connected machine)
// Submit the transaction to the network
// const transferTxId = await networkClient.submitTransaction(transferTx);
//---------------------------------------------------------
//---------------------------------------------------------
22 changes: 11 additions & 11 deletions create-leo-app/template-react-leo/src/workers/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ async function localProgramExecution(program, aleoFunction, inputs) {
const account = new Account();
programManager.setAccount(account);

const executionResponse = await programManager.run(
const executionResponse = await programManager.run({
program,
aleoFunction,
programName: aleoFunction,
inputs,
false,
);
proveExecution: false,
});
return executionResponse.getOutputs();
}

Expand All @@ -37,33 +37,33 @@ async function deployProgram(program) {
keyProvider.useCache(true);

// Create a record provider that will be used to find records and transaction data for Aleo programs
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const networkClient = new AleoNetworkClient({ host: "https://api.explorer.provable.com/v1" });

// Use existing account with funds
const account = new Account({
privateKey: "user1PrivateKey",
});

const recordProvider = new NetworkRecordProvider(account, networkClient);
const recordProvider = new NetworkRecordProvider({ account, networkClient });

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

programManager.setAccount(account);

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

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

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

return tx_id;
}
Expand Down
7 changes: 6 additions & 1 deletion create-leo-app/template-react-managed-worker/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ function App() {
" output r2 as u32.private;\n";

setLoading(true);
const result = await aleoWorker.run(hello_hello_program,"hello", ["5u32", "5u32"], "APrivateKey1zkp778oUFSck3PZA5xppgp4trFwkkD6xnUXtxcBCfsq4URJ")
const result = await aleoWorker.run({
program: hello_hello_program,
functionName: "hello",
inputs: ["5u32", "5u32"],
privateKey: "APrivateKey1zkp778oUFSck3PZA5xppgp4trFwkkD6xnUXtxcBCfsq4URJ",
});
setLoading(false);

alert(JSON.stringify(result));
Expand Down
22 changes: 11 additions & 11 deletions create-leo-app/template-react-ts/src/workers/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ async function localProgramExecution(program, aleoFunction, inputs) {
const account = new Account();
programManager.setAccount(account);

const executionResponse = await programManager.run(
const executionResponse = await programManager.run({
program,
aleoFunction,
functionName: aleoFunction,
inputs,
false,
);
proveExecution: false,
});
return executionResponse.getOutputs();
}

Expand All @@ -38,33 +38,33 @@ async function deployProgram(program) {
keyProvider.useCache(true);

// Create a record provider that will be used to find records and transaction data for Aleo programs
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const networkClient = new AleoNetworkClient({ host: "https://api.explorer.provable.com/v1" });

// Use existing account with funds
const account = new Account({
privateKey: "user1PrivateKey",
});

const recordProvider = new NetworkRecordProvider(account, networkClient);
const recordProvider = new NetworkRecordProvider({ account, networkClient });

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

programManager.setAccount(account);

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

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

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

return tx_id;
}
Expand Down
Loading
Loading