### Install Dependencies and Start Development Server Source: https://github.com/provablehq/sdk/blob/mainnet/website/README.md Run these commands in the project directory to install dependencies and start the development server. Open http://localhost:5173 to view the site in the browser. ```bash yarn yarn dev ``` -------------------------------- ### Install and Run with NPM Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-private-transaction-ts/README.md Use this command to install dependencies and run the example using NPM. Ensure Node.js 20+ is installed for optimal performance. ```bash npm start ``` -------------------------------- ### Install and Run Development Server Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-react-credits-aleo-functions-ts/README.md Installs project dependencies and starts the development server. Ensure network connectivity for the app to function. ```bash npm install npm run dev ``` -------------------------------- ### Install and Run with Yarn Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-private-transaction-ts/README.md Use this command to install dependencies and run the example using Yarn. Ensure Node.js 20+ is installed for optimal performance. ```bash yarn start ``` -------------------------------- ### Start Development Server (Webpack) Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-react-loyalty-program-ts/README.md Alternatively, start the development server using Webpack. ```bash npm run dev-webpack ``` -------------------------------- ### Install Dependencies and Run Demo Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-node-loyalty-program-ts/README.md Install project dependencies and run the full demo flow using npm. Supports local proving, delegated proving via DPS, and record scanning. ```bash npm install npm start npm run local npm run delegated npm run scanner npm run start:mint npm run start:add npm run start:redeem ``` -------------------------------- ### Install Provable SDK Source: https://context7.com/provablehq/sdk/llms.txt Install the SDK using npm or yarn. ```bash npm install @provablehq/sdk # or yarn add @provablehq/sdk ``` -------------------------------- ### Copy Environment Example Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-react-leo/README.md Before configuring your .env file, copy the example environment file. This file is ignored by Git and contains necessary configuration variables. ```bash cd helloworld cp .env.example .env ``` -------------------------------- ### Start Development Server (Vite) Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-react-loyalty-program-ts/README.md Run the development server using Vite for a fast development experience. This is the recommended approach. ```bash npm run dev ``` -------------------------------- ### Install Dependencies Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-react-loyalty-program-ts/README.md Install project dependencies using npm or yarn. Ensure Node.js 18+ is installed. ```bash npm install ``` -------------------------------- ### Install Provable SDK via NPM Source: https://github.com/provablehq/sdk/blob/mainnet/docs/guide/02_setup.md Install the Provable SDK using the npm package manager. ```bash npm install @provablehq/sdk ``` -------------------------------- ### Install Provable SDK via Yarn Source: https://github.com/provablehq/sdk/blob/mainnet/docs/guide/02_setup.md Install the Provable SDK using the yarn package manager. ```bash yarn add @provablehq/sdk ``` -------------------------------- ### Initialize AleoNetworkClient and Get Block by Hash Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_network-client.md Demonstrates how to initialize the AleoNetworkClient and retrieve a block using its hash. ```javascript import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined); const block = networkClient.getBlockByHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9"); ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-node-loyalty-program-ts/README.md Copy the example environment file and configure necessary variables for consumer ID, delegated proving, and record scanning. ```bash # Consumer ID (used for both DPS and RSS) ALEO_CONSUMER_ID=your-consumer-id # For delegated mode ALEO_PROVING_MODE=delegated ALEO_DPS_URL=https://api.provable.com/prove/testnet ALEO_DPS_API_KEY=your-api-key # For record scanning ALEO_RSS_URL=https://api.provable.com/scanner ``` -------------------------------- ### Run Development Server Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-nextjs-ts/README.md Execute this command to start the Next.js development server. Open http://localhost:3000 in your browser to view the application. ```bash yarn dev ``` -------------------------------- ### Run All Credits.aleo Functions Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-node-credits-aleo-functions-ts/README.md Execute all 6 credits.aleo functions using the start script. This command requires network connectivity. ```bash yarn start # or npm run start ``` -------------------------------- ### Initialize Leo Devnode Server Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-devnode-js/README.md Starts the Leo Devnode server with a specified private key. Optional verbosity levels (0, 1, 2) can be set. ```bash leo devnode start --private-key APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH ``` -------------------------------- ### Run Single Credits.aleo Function Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-node-credits-aleo-functions-ts/README.md Execute a specific credits.aleo function by passing its name as an argument to the start script. This command requires network connectivity. ```bash yarn start transfer_public # or npm run start -- transfer_public ``` -------------------------------- ### Initialize Program Manager and Execute Program Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_program-manager.md Demonstrates initializing the Program Manager with a key provider and executing a program. Ensure you have the necessary network clients and account information set up. ```javascript /// Import the mainnet version of the sdk. import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js"; // Create a new NetworkClient, KeyProvider, and RecordProvider const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); keyProvider.useCache(true); // Initialize a program manager with the key provider to automatically fetch keys for executions const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); const record = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}" const tx_id = await programManager.split(25000000, record); // Verify the transaction was successful setTimeout(async () => { const transaction = await programManager.networkClient.getTransaction(tx_id); assert(transaction.id() === tx_id); }, 10000); ``` -------------------------------- ### Initialize Program Manager with Key Provider Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_function-key-provider.md Demonstrates initializing the `ProgramManager` with an `AleoKeyProvider` and `NetworkRecordProvider` to automatically fetch keys for value transfers. Keys can also be fetched manually. ```javascript const networkClient = new AleoNetworkClient("https://api.provable.com/v2"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager with the key provider to automatically fetch keys for value transfers const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); // Keys can also be fetched manually using the key provider const keySearchParams = { "cacheKey": "myProgram:myFunction" }; const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.functionKeys(keySearchParams); ``` -------------------------------- ### Build and Publish Packages Source: https://github.com/provablehq/sdk/blob/mainnet/PUBLISH.md Execute these commands sequentially to build, log in, and publish all packages. Ensure you replace `$VERSION` with the correct version number for tagging. ```bash yarn build:all npm login cd wasm && npm publish --access public cd ../sdk && npm publish --access public cd ../create-leo-app & npm publish --access public git tag vX.X.X git push origin vX.X.X ``` -------------------------------- ### transactionType Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_wasm.md Gets the type of the transaction, which can be 'deploy' or 'execute'. ```APIDOC ## transactionType() ► string ### Description Get the type of the transaction (will return "deploy" or "execute") ### Returns - `string` - *Transaction type* ``` -------------------------------- ### getKeys(keyId) Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_function-key-provider.md Get a set of keys from the cache. ```APIDOC ## getKeys(keyId) ### Description Get a set of keys from the cache. ### Parameters #### Path Parameters - **keyId** (undefined) - Required - keyId of a proving and verifying key pair ### Return - **FunctionKeyPair** - Proving and verifying keys for the specified program ``` -------------------------------- ### Create and Configure OfflineKeyProvider Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_offline-key-provider.md Demonstrates setting up a ProgramManager with an Account, loading local keys, creating an OfflineKeyProvider, caching necessary keys, and initializing an OfflineQuery and OfflineSearchParams for transaction building. ```javascript const programManager = new ProgramManager(); const account = new Account(); programManager.setAccount(account); console.log("Creating proving keys from local key files"); const program = "program hello_hello.aleo; function hello: input r0 as u32.public; input r1 as u32.private; add r0 r1 into r2; output r2 as u32.private;"; const myFunctionProver = await getLocalKey("/path/to/my/function/hello_hello.prover"); const myFunctionVerifier = await getLocalKey("/path/to/my/function/hello_hello.verifier"); const feePublicProvingKeyBytes = await getLocalKey("/path/to/credits.aleo/feePublic.prover"); myFunctionProvingKey = ProvingKey.fromBytes(myFunctionProver); myFunctionVerifyingKey = VerifyingKey.fromBytes(myFunctionVerifier); const feePublicProvingKey = ProvingKey.fromBytes(feePublicKeyBytes); console.log("Creating offline key provider"); const offlineKeyProvider = new OfflineKeyProvider(); OfflineKeyProvider.cacheKeys("hello_hello.aleo/hello", myFunctionProvingKey, myFunctionVerifyingKey); OfflineKeyProvider.insertFeePublicKey(feePublicProvingKey); const offlineQuery = new OfflineQuery("latestStateRoot"); programManager.setKeyProvider(offlineKeyProvider); const offlineSearchParams = new OfflineSearchParams("hello_hello.aleo/hello"); const offlineExecuteTx = await this.buildExecutionTransaction("hello_hello.aleo", "hello", 1, false, ["5u32", "5u32"], undefined, offlineSearchParams, undefined, undefined, undefined, undefined, offlineQuery, program); const networkClient = new AleoNetworkClient("https://api.provable.com/v2"); const txId = await networkClient.broadcastTransaction(offlineExecuteTx); ``` -------------------------------- ### functionKeys(params) Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_function-key-provider.md Get arbitrary function keys from a provider. ```APIDOC ## functionKeys(params) ### Description Get arbitrary function keys from a provider. ### Parameters #### Path Parameters - **params** (KeySearchParams) - Required - parameters for the key search in form of: {proverUri: string, verifierUri: string, cacheKey: string} ### Return - **Promise.** - Proving and verifying keys for the specified program ### Examples ```javascript // Create a new object which implements the KeyProvider interface const networkClient = new AleoNetworkClient("https://api.provable.com/v2"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager with the key provider to automatically fetch keys for value transfers const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); // Keys can also be fetched manually using the key provider const keySearchParams = { "cacheKey": "myProgram:myFunction" }; const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.functionKeys(keySearchParams); ``` ``` -------------------------------- ### id Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_wasm.md Gets the unique ID of the transaction, which is the Merkle root of its inclusion proof. ```APIDOC ## id() ► string ### Description Get the id of the transaction. This is the merkle root of the transaction's inclusion proof. This value can be used to query the status of the transaction on the Aleo Network to see if it was successful. If successful, the transaction will be included in a block and this value can be used to lookup the transaction data on-chain. ### Returns - `string` - *TransactionId* ``` -------------------------------- ### Initialize and Use AleoKeyProvider Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_function-key-provider.md Demonstrates the initialization of AleoKeyProvider and its integration with ProgramManager for automatic key fetching during value transfers. It also shows how to manually fetch transfer keys. ```javascript const networkClient = new AleoNetworkClient("https://api.provable.com/v2"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager with the key provider to automatically fetch keys for value transfers const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); // Keys can also be fetched manually const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public"); ``` -------------------------------- ### Initialize ProgramManager with KeyProvider Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_function-key-provider.md Demonstrates initializing a ProgramManager with an AleoKeyProvider for automatic key fetching during value transfers. Keys can also be fetched manually. ```javascript const networkClient = new AleoNetworkClient("https://api.provable.com/v2"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.fetchKeys( CREDITS_PROGRAM_KEYS.transfer_private.prover, CREDITS_PROGRAM_KEYS.transfer_private.verifier, ); ``` -------------------------------- ### Get Latest Block Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_network-client.md Fetches the contents of the most recent block on the Aleo network. ```javascript import { AleoNetworkClient } from "@provablehq/sdk/testnet.js"; // Create a network client. const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined); const latestHeight = networkClient.getLatestBlock(); ``` -------------------------------- ### Get ProvingRequest Authorization Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_wasm.md Retrieves the Authorization object associated with the main function of the ProvingRequest. ```javascript const auth = provingRequest.authorization(); ``` -------------------------------- ### Initialize and Use NetworkRecordProvider Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_record-provider.md Demonstrates the initialization of NetworkRecordProvider with an AleoNetworkClient and its subsequent use for finding credit records. It also shows how to manage nonces to avoid duplicate record retrieval and how the provider integrates with ProgramManager for automated record finding in transfers. ```typescript const networkClient = new AleoNetworkClient("https://api.provable.com/v2"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // The record provider can be used to find records with a given number of microcredits const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] }); // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not // found again if a subsequent search is performed const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] }); // When the program manager is initialized with the record provider it will be used to find automatically find // fee records and amount records for value transfers so that they do not need to be specified manually const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); ``` -------------------------------- ### Get Transaction by ID Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_network-client.md Retrieves a transaction by its unique identifier. Requires an initialized AleoNetworkClient. ```javascript import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; // Create a network client. const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined); const transaction = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj"); ``` -------------------------------- ### Get Current Account Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_network-client.md Retrieve the Aleo account currently configured for the network client. ```javascript const account = networkClient.getAccount(); ``` -------------------------------- ### Deploy Aleo Program using ProgramManager Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_program-manager.md Demonstrates how to initialize a ProgramManager and build a deployment transaction for an Aleo program. Ensure you have the necessary network clients and account information set up. ```javascript /// Import the mainnet version of the sdk. import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js"; // Create a new NetworkClient, KeyProvider, and RecordProvider const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); keyProvider.useCache(true); // Initialize a program manager with the key provider to automatically fetch keys for deployments 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"; const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); programManager.setAccount(Account); // Define a fee in credits const priorityFee = 0.0; // Create the deployment transaction. const tx = await programManager.buildDeploymentTransaction(program, fee, false); await programManager.networkClient.submitTransaction(tx); // Verify the transaction was successful setTimeout(async () => { const transaction = await programManager.networkClient.getTransaction(tx.id()); assert(transaction.id() === tx.id()); }, 20000); ``` -------------------------------- ### Get ProvingRequest Fee Authorization Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_wasm.md Retrieves the fee Authorization object from the ProvingRequest. This is used for paying the execution fee. ```javascript const feeAuth = provingRequest.feeAuthorization(); ``` -------------------------------- ### Initialize ProgramManager and Build Fee Authorizations Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_program-manager.md Demonstrates initializing the ProgramManager with key and record providers, and building both public and private fee authorizations for Aleo transactions. Ensure you have the necessary account and networkClient objects initialized. ```javascript /// Import the mainnet version of the sdk. import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js"; // Create a new NetworkClient, KeyProvider, and RecordProvider. const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); keyProvider.useCache(true); // Initialize a ProgramManager with the key and record providers. const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); // Build a credits.aleo/fee_public `Authorization`. const feePublicAuthorization = await programManager.buildFeeAuthorization({ deploymentOrExecutionId: "2423957656946557501636078245035919227529640894159332581642187482178647335171field", baseFeeCredits: 0.1, }); // Build a credits.aleo/fee_private `Authorization`. const record = "{ owner: aleo1j7qxyunfldj2lp8hsvy7mw5k8zaqgjfyr72x2gh3x4ewgae8v5gscf5jh3.private, microcredits: 1500000000000000u64.private, _nonce: 3077450429259593211617823051143573281856129402760267155982965992208217472983group.public }"; const feePrivateAuthorization = await programManager.buildFeeAuthorization({ deploymentOrExecutionId: "2423957656946557501636078245035919227529640894159332581642187482178647335171field", baseFeeCredits: 0.1, feeRecord: record, }); ``` -------------------------------- ### getCreditsProgram() ► Program Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_wasm.md Get the credits.aleo program. This static method provides access to the pre-defined credits program. ```APIDOC ## getCreditsProgram() ► Program ### Description Get the credits.aleo program ### Parameters *None* #### Return - **Program** - The credits.aleo program ``` -------------------------------- ### Initialize and Use Loyalty Program SDK Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-node-loyalty-program-ts/README.md Instantiate the LoyaltyProgram, set the Aleo programs, and perform core operations like minting cards, adding points, and redeeming vouchers. ```typescript import { LoyaltyProgram, RewardType, CardTier } from "./index"; // Create instance with an account const loyalty = new LoyaltyProgram(account); loyalty.setPrograms(tokenProgram, rewardsProgram); // Mint a new loyalty card const card = await loyalty.mintCard(address, 1000); // => LoyaltyCard { owner, cardId, points: 1000, tier: Bronze } // Add points (consumes old card, creates new) const updatedCard = await loyalty.addPoints(card, 500); // => LoyaltyCard { points: 1500, tier: Silver } // Redeem points for a voucher (multi-program execution) const { card: newCard, voucher } = await loyalty.redeemForVoucher( updatedCard, RewardType.Discount, 500 ); // => { card: LoyaltyCard, voucher: RewardVoucher } // Use (burn) the voucher await loyalty.useVoucher(voucher); // Find on-chain records (requires RecordScanner) const myCards = await loyalty.findMyCards(); const myVouchers = await loyalty.findMyVouchers(); ``` -------------------------------- ### Deploy Aleo Program with Program Manager Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_program-manager.md Demonstrates how to deploy an Aleo program using the ProgramManager. Ensure the SDK is imported and initialized with appropriate network clients and providers. The program definition and fee are specified before initiating the deployment. ```javascript /// Import the mainnet version of the sdk. import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js"; // Create a new NetworkClient, KeyProvider, and RecordProvider. const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); keyProvider.useCache(true); // Initialize a program manager with the key provider to automatically fetch keys for deployments 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;"; const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); // Define a fee in credits const priorityFee = 0.0; // Deploy the program const tx_id = await programManager.deploy(program, fee, false); // Verify the transaction was successful setTimeout(async () => { const transaction = await programManager.networkClient.getTransaction(tx_id); assert(transaction.id() === tx_id); }, 20000); ``` -------------------------------- ### Get Confirmed Transaction by ID Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_network-client.md Retrieves a confirmed transaction by its unique identifier. Asserts that the transaction status is 'confirmed'. ```javascript import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; // Create a network client. const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined); const transaction = networkClient.getConfirmedTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj"); assert.equal(transaction.status, "confirmed"); ``` -------------------------------- ### Get Account View Key Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_account.md Returns the view key for the account, which can be used for decrypting user activity on the blockchain. ```javascript import { Account } from "@provablehq/sdk/testnet.js"; const account = new Account(); const viewKey = account.viewKey(); ``` -------------------------------- ### Build for Production (Vite) Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-react-loyalty-program-ts/README.md Create a production build of the application using Vite. ```bash npm run build:vite ``` -------------------------------- ### Initialize Multithreaded WebAssembly Source: https://github.com/provablehq/sdk/blob/mainnet/docs/guide/02_setup.md Enable multithreaded WebAssembly by calling initThreadPool. This should be done once at the application's start before any other SDK functions. ```typescript import { Account, initThreadPool } from '@provablehq/sdk/mainnet.js'; // Enables multithreading await initThreadPool(); // Create a new Aleo account const account = new Account(); // Perform further program logic... ``` -------------------------------- ### Initialize and Cache Transfer Public Keys Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_offline-key-provider.md Demonstrates how to initialize an OfflineKeyProvider, read binary proving keys from a file, and insert them into the cache for future use. The SDK automatically caches the corresponding verifying key. ```javascript const offlineKeyProvider = new OfflineKeyProvider(); const transferPublicProvingKeyBytes = await readBinaryFile('./resources/transfer_public.prover.a74565e'); const transferPublicProvingKey = ProvingKey.fromBytes(transferPublicProvingKeyBytes); offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey); ``` -------------------------------- ### Initialize SDK and Build Public-to-Private Transfer Source: https://github.com/provablehq/sdk/blob/mainnet/docs/examples/02_transfer_private.md Initializes the SDK, sets up network clients, and builds a public-to-private transfer transaction. Ensure you have the necessary network endpoints and account credentials. ```typescript import { Account, ProgramManager, initThreadPool } from '@provable.sdk'; // Initialize multi-threading to allow WASM execution. await initThreadPoool(); // Create an account. const account = new Account(); // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers const networkClient = new AleoNetworkClient("https://api.provable.com/v2"); const keyProvider = new AleoKeyProvider(); keyProvider.useCache(true);; const recordProvider = new NetworkRecordProvider(account, networkClient); // Create program manager using the KeyProvider and NetworkProvider. const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); // Set the account as the program caller. programManager.setAccount(account); // Build a transfer_public_to_private transaction. // Create a credits record for the sender. const transaction = await programManager .buildTransferTransaction( 5, // The amount to be transferred in credits (not microcredits) account // The address of the recipient (In this case, your own address). .address() .to_string(), "publicToPrivate", // The transfer type. 0.0, // The optional priority fee amount. false, // Indicates whether or not the fee will be private. ); // Broadcast the transaction to the Aleo network. let result = await programManager.networkClient.submitTransaction(transaction); let transactionObj; let transactionFound = false; // Loop until the transaction has been Accepted while (!transactionFound) { try { transactionObj = await programManager.networkClient.getTransactionObject(result); transactionFound = true; } catch (e) { console.error(e); } } // Get the list of owned records attached to the transaction. let transactionRecords = transactionObj.ownedRecords(account.viewKey()); // This transaction only contains one record so it is the first and only one. let record = transactionRecords[0]; // This new account will stand in as the recipient in this transfer. const recipient = new Account(); // Build a transfer_private transaction. // Privately send 5 microcredits to the recipient from the sender's record const transaction2 = await programManager .buildTransferTransaction( 5, // The amount to be transferred in credits (not microcredits) recipient // The address of the recipient. .address() .to_string(), "private", // The transfer type. 0.0, // The optional priority fee amount. false, // Indicates whether or not the fee will be private. ); // Broadcast the transaction to the Aleo network. const result2 = await programManager.networkClient.submitTransaction(transaction2); // ``` -------------------------------- ### Get Transactions by Block Hash Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_network-client.md Fetches confirmed transactions associated with a specific block hash. Requires an initialized AleoNetworkClient. ```javascript import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; // Create a network client. const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined); const transactions = networkClient.getTransactionsByBlockHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9"); ``` -------------------------------- ### Directly Deploy Aleo Program Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_program-manager.md This example demonstrates deploying an Aleo program directly using the `deploy` method of the ProgramManager. It handles transaction creation and submission, returning the transaction ID upon success. ```javascript /// Import the mainnet version of the sdk. import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js"; // Create a new NetworkClient, KeyProvider, and RecordProvider. const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); keyProvider.useCache(true); // Initialize a program manager with the key provider to automatically fetch keys for deployments 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"; const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); // Define a fee in credits const priorityFee = 0.0; // Deploy the program const tx_id = await programManager.deploy(program, fee, false); // Verify the transaction was successful setTimeout(async () => { const transaction = await programManager.networkClient.getTransaction(tx_id); assert(transaction.id() === tx_id); }, 20000); ``` -------------------------------- ### Get Transactions by Block Height Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_network-client.md Retrieves all confirmed transactions that occurred at a specific block height. Requires an initialized AleoNetworkClient. ```javascript import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; // Create a network client. const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined); const transactions = networkClient.getTransactions(654); ``` -------------------------------- ### Execute and Verify Aleo Program with Imports Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_program-manager.md Demonstrates how to set up an account, run a program with external imports, and verify its execution. Ensure you have your Aleo ciphertext and password set as environment variables. ```javascript /// Import the mainnet version of the sdk used to build executions. import { Account, ProgramManager } from "@provablehq/sdk/mainnet.js"; /// Create the source for two programs. const program = "import add_it_up.aleo; program mul_add.aleo; function mul_and_add:\n input r0 as u32.public; input r1 as u32.private; mul r0 r1 into r2; call add_it_up.aleo/add_it r1 r2 into r3; output r3 as u32.private;"; const program_import = "program add_it_up.aleo;\n\nfunction add_it:\n input r0 as u32.public; input r1 as u32.private; add r0 r1 into r2; output r2 as u32.private;"; const programManager = new ProgramManager(undefined, undefined, undefined); /// Create a temporary account for the execution of the program const account = Account.fromCipherText(process.env.ciphertext, process.env.password); programManager.setAccount(account); /// Get the response and ensure that the program executed correctly const executionResponse = await programManager.run(program, "mul_and_add", ["5u32", "5u32"], true); /// Construct the imports and verifying keys const imports = { "add_it_up.aleo": program_import }; const importedVerifyingKeys = { "add_it_up.aleo": [["add_it", "verifyingKey1..."]] }; /// Verify the execution. const blockHeight = 9000000; const isValid = programManager.verifyExecution(executionResponse, blockHeight, imports, importedVerifyingKeys); assert(isValid); ``` -------------------------------- ### Get Latest Committee using AleoNetworkClient Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_network-client.md Fetches the most recent committee information from the Aleo Network. Requires an initialized AleoNetworkClient. ```javascript import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; // Create a network client. const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined); // Create a network client and get the latest committee. const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined); const latestCommittee = await networkClient.getLatestCommittee(); ``` -------------------------------- ### Initialize ProgramManager and Perform Transfers Source: https://github.com/provablehq/sdk/blob/mainnet/docs/guide/05_transfers.md Sets up the necessary SDK components and demonstrates various transfer operations: private to self, public to self, public to another user, and public to private. Ensure the account is set on the program manager before initiating transfers. ```typescript import { Account, ProgramManager, AleoKeyProvider, NetworkRecordProvider, AleoNetworkClient } from '@provablehq/sdk'; // Create a new NetworkClient, KeyProvider, and RecordProvider const account = Account.from_string({privateKey: "user1PrivateKey"}); const networkClient = new AleoNetworkClient("https://api.provable.com/v2"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager with the key provider to automatically fetch keys for executions const myAddress = account.address(); const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); programManager.setAccount(account); // Send a private transfer to yourself const tx_id = await programManager.transfer(1, myAddress, "transfer_private", 0.2); // Update or initialize a public balance in your own account mapping const tx_id_2 = await programManager.transfer(1, myAddress, "transfer_private_to_public", 0.2); // Check the value of your public balance let public_balance = programManager.networkClient.getMappingValue("credits.aleo", myAddress); assert(public_balance === 0.2*1_000_000); /// Send public transfer to another user const USER_2_ADDRESS = "user2Address"; const tx_id_3 = await programManager.transfer(1, USER_2_ADDRESS, "transfer_public", 0.1); // Check the value of the public balance and assert that it has been updated public_balance = programManager.networkClient.getMappingValue("credits.aleo", myAddress); const user2_public_balance = programManager.networkClient.getMappingValue("credits.aleo", myAddress); assert(public_balance === 0.1*1_000_000); assert(user2_public_balance === 0.1*1_000_000); /// Create a private record from a public balance const tx_id_4 = await programManager.transfer(1, myAddress, "transfer_public_to_private", 0.1); // Check the value of the public balance and assert that it has been updated public_balance = programManager.networkClient.getMappingValue("credits.aleo", myAddress); assert(public_balance === 0); ``` -------------------------------- ### Get Account Address Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_account.md Fetches the public Aleo address associated with the account. This address can be shared for receiving credits and records. ```javascript import { Account } from "@provablehq/sdk/testnet.js"; const account = new Account(); const address = account.address(); ``` -------------------------------- ### Leo "Hello World" Program Source: https://github.com/provablehq/sdk/blob/mainnet/docs/guide/04_programs.md A basic Leo program demonstrating a public transition that adds two unsigned 32-bit integers and returns the result. ```leo program helloworld.aleo { transition hello(public a: u32, b: u32) -> u32 { let c: u32 = a + b; return c; } } ``` -------------------------------- ### Get feePublicKeys Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_function-key-provider.md Fetches the proving and verifying keys for the fee_public function in the credits.aleo program. This is used for public fee settlements. ```javascript const [feePublicProvingKey, feePublicVerifyingKey] = await keyProvider.feePublicKeys(); ``` -------------------------------- ### Using NetworkRecordProvider for Fee Payment Source: https://github.com/provablehq/sdk/blob/mainnet/docs/guide/10_finding_records.md Demonstrates initializing NetworkClient, KeyProvider, and NetworkRecordProvider, then using ProgramManager to find and submit a transaction with an automatically selected fee record. ```typescript import { AleoNetworkClient, AleoKeyProvider, NetworkRecordProvider, ProgramManager } from '@provablehq/sdk'; // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers const networkClient = new AleoNetworkClient("https://api.provable.com/v2"); const keyProvider = new AleoKeyProvider(); keyProvider.useCache(true); const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager with the key provider to automatically fetch keys for executions const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); // Find a record to pay the fee for the transaction let inputRecordSearchParameters = { programs: ["credits.aleo"], // Find records for the credits.aleo program. amounts: [10_000_000], // Find the amount desired to be transferred. startHeight: 4370000, // Specify the start of a block range where unspent records are likely to be found. endHeight: 4371000, // Specify the end of a block height range where unspent records are likely to be found. } const record = await programManager.recordProvider.findRecords( true, // Find only unspent records. undefined, // No nonces need to be excluded because only one record is being searched for. inputRecordSearchParameters, ); // Record the nonce of the found record so it's not selected again. const nonce = record.nonce(); const feeRecordSearchParameters = { programs: ["credits.aleo"], // Find records for the credits.aleo program. amounts: [40_000], // Find the amount desired to be transferred. startHeight: 4370000, // Specify the start height. endHeight: 4371000, // Specify the end height. nonces: [nonce], // Exclude the nonce of the record found for the transfer. } const transaction = await programManager.buildExecutionTransaction({ programName: "credits.aleo", functionName: "transfer_private", fee: 0.040, privateFee: true, inputs: ["aleoAddress1..", "10000000u64"], recordSearchParams: feeRecordSearchParameters, // Specify the record search parameters for the fee record. }); const result = await programManager.networkClient.submitTransaction(transaction); ``` -------------------------------- ### Get feePrivateKeys Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_function-key-provider.md Obtains the proving and verifying keys for the fee_private function in the credits.aleo program. This is used for private fee settlements. ```javascript const [feePrivateProvingKey, feePrivateVerifyingKey] = await keyProvider.feePrivateKeys(); ``` -------------------------------- ### getFunctions() ► Array Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_wasm.md Get a javascript array of function names in the program. This is useful for understanding the callable functions within a program. ```APIDOC ## getFunctions() ► Array ### Description Get javascript array of functions names in the program ### Parameters *None* #### Return - **Array** - Array of all function names present in the program #### Examples ```javascript const expected_functions = [ "mint", "transfer_private", "transfer_private_to_public", "transfer_public", "transfer_public_to_private", "join", "split", "fee" ] const credits_program = aleo_wasm.Program.getCreditsProgram(); const credits_functions = credits_program.getFunctions(); console.log(credits_functions === expected_functions); // Output should be "true" ``` ``` -------------------------------- ### Run and Verify Aleo Program Execution Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_program-manager.md Demonstrates how to set up an account, run a program with specific inputs, and verify its execution using the ProgramManager. Ensure your environment variables for ciphertext and password are set. ```javascript /// Import the mainnet version of the sdk used to build executions. import { Account, ProgramManager } from "@provablehq/sdk/mainnet.js"; /// Create the source for two programs. const program = "import add_it_up.aleo; program mul_add.aleo; function mul_and_add: input r0 as u32.public; input r1 as u32.private; mul r0 r1 into r2; call add_it_up.aleo/add_it r1 r2 into r3; output r3 as u32.private;"; const program_import = "program add_it_up.aleo;\n\nfunction add_it:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;"; const programManager = new ProgramManager(undefined, undefined, undefined); /// Create a temporary account for the execution of the program const account = Account.fromCipherText(process.env.ciphertext, process.env.password); programManager.setAccount(account); /// Get the response and ensure that the program executed correctly const executionResponse = await programManager.run(program, "mul_and_add", ["5u32", "5u32"], true); /// Construct the imports and verifying keys const imports = { "add_it_up.aleo": program_import }; const importedVerifyingKeys = { "add_it_up.aleo": [["add_it", "verifyingKey1..."]] }; /// Verify the execution. const blockHeight = 9000000; const isValid = programManager.verifyExecution(executionResponse, blockHeight, imports, importedVerifyingKeys); assert(isValid); ``` -------------------------------- ### Network Selection and WebAssembly Initialization Source: https://context7.com/provablehq/sdk/llms.txt Import from the correct network path (mainnet.js or testnet.js) and call initThreadPool once at app startup to enable multi-threaded proof generation. ```APIDOC ## Network Selection and WebAssembly Initialization ### Description Import from the correct network path (`mainnet.js` or `testnet.js`) and call `initThreadPool` once at app startup to enable multi-threaded proof generation. ### Usage ```typescript // Mainnet import import { Account, ProgramManager, AleoKeyProvider, initThreadPool } from '@provablehq/sdk/mainnet.js'; // Testnet import import { Account, ProgramManager, AleoKeyProvider, initThreadPool } from '@provablehq/sdk/testnet.js'; // Default (testnet) import { Account, ProgramManager, initThreadPool } from '@provablehq/sdk'; // MUST be called once before any other SDK operation. // Enables multi-threaded WASM for high-performance proof generation. await initThreadPool(); ``` ``` -------------------------------- ### Get Program Functions Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_wasm.md Retrieves a list of all function names available in the credits.aleo program. This is useful for dynamic function discovery and validation. ```javascript const expected_functions = [ "mint", "transfer_private", "transfer_private_to_public", "transfer_public", "transfer_public_to_private", "join", "split", "fee" ] const credits_program = aleo_wasm.Program.getCreditsProgram(); const credits_functions = credits_program.getFunctions(); console.log(credits_functions === expected_functions); // Output should be "true" ``` -------------------------------- ### Get Program Mappings Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_wasm.md Retrieves the mappings defined within the credits.aleo program. Useful for understanding data structures associated with credits. ```javascript const expected_mappings = [ { name: "account", key_name: "owner", key_type: "address", value_name: "microcredits", value_type: "u64" } ] const credits_program = aleo_wasm.Program.getCreditsProgram(); const credits_mappings = credits_program.getMappings(); console.log(credits_mappings === expected_mappings); // Output should be "true" ``` -------------------------------- ### Get Committee by Block Height Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_network-client.md Fetches the committee information for a specific block height. This allows for historical analysis of network consensus. ```javascript const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined); // Get the committee at a specific block height. const committee = await networkClient.getCommitteeByBlockHeight(12345); ``` -------------------------------- ### Build for Production (Webpack) Source: https://github.com/provablehq/sdk/blob/mainnet/create-leo-app/template-react-loyalty-program-ts/README.md Create a production build of the application using Webpack. ```bash npm run build ``` -------------------------------- ### Get Public Balance Source: https://github.com/provablehq/sdk/blob/mainnet/docs/api_reference/sdk-src_network-client.md Retrieves the public balance of an Aleo address. Accepts an address object or string. The balance is returned in microcredits. ```javascript import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; // Create a network client. const networkClient = new AleoNetworkClient("https://api.provable.com/v2", undefined); // Get the balance of an account from either an address object or address string. const account = Account.fromCiphertext(process.env.ciphertext, process.env.password); const publicBalance = await networkClient.getPublicBalance(account.address()); const publicBalanceFromString = await networkClient.getPublicBalance(account.address().to_string()); assert(publicBalance === publicBalanceFromString); ``` -------------------------------- ### TypeScript: Private Value Transfer with SDK Source: https://github.com/provablehq/sdk/blob/mainnet/docs/guide/09_private_program_state.md Demonstrates how to initiate a private value transfer using the Aleo SDK. This involves setting up account credentials, network clients, and a program manager to execute the transfer function. ```typescript // USER 1 import { Account, ProgramManager, AleoKeyProvider, NetworkRecordProvider, AleoNetworkClient } from '@provablehq/sdk'; // Create a new NetworkClient, KeyProvider, and RecordProvider const account = Account.from_string({privateKey: "user1PrivateKey"}); const networkClient = new AleoNetworkClient("https://api.provable.com/v2"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager with the key provider to automatically fetch keys for executions const USER_2_ADDRESS = "user2Address"; const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider); programManager.setAccount(account); /// Send private transfer to User 2 const tx_id = await programManager.transfer(1, USER_2_ADDRESS, "transfer_private", 0.2); ```