### Install Provable SDK with NPM Source: https://docs.explorer.provable.com/docs/sdk/iv67tt1dqrsli-setup Installs the Provable SDK using the npm package manager. This is a prerequisite for using the SDK in your project. ```bash npm install @provablehq/sdk ``` -------------------------------- ### Install Provable SDK with Yarn Source: https://docs.explorer.provable.com/docs/sdk/iv67tt1dqrsli-setup Installs the Provable SDK using the yarn package manager. This is an alternative to npm for installing the SDK. ```bash yarn add @provablehq/sdk ``` -------------------------------- ### Import Mainnet Network Module Source: https://docs.explorer.provable.com/docs/sdk/iv67tt1dqrsli-setup Imports necessary classes and functions from the Provable SDK specifically for the mainnet network. This ensures transactions are built for the correct network. ```javascript import { Account, ProgramManager, initThreadPool } from '@provablehq/sdk/mainnet.js'; ``` -------------------------------- ### Program Execution Example Source: https://docs.explorer.provable.com/docs/sdk/642b6790602a0-wasm Example of how to execute a program using the ProgramManager, including setting up an account and verifying the execution result. ```APIDOC ## Program Execution Example ### Description This example demonstrates how to compile and execute a simple Aleo program ('helloworld'). It includes setting up a temporary account and program manager, running the program with specified inputs, and asserting the correctness of the output. ### Method Not applicable (Client-side JavaScript example) ### Endpoint Not applicable (Client-side JavaScript example) ### Parameters None (Client-side JavaScript example) ### Request Example ```javascript import { Account, Program } from '@provablehq/sdk'; /// Create the source for the "helloworld" program 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;"; const programManager = new ProgramManager(); /// Create a temporary account for the execution of the program const account = new Account(); programManager.setAccount(account); /// Get the response and ensure that the program executed correctly const executionResponse = await programManager.run(program, "hello", ["5u32", "5u32"]); const result = executionResponse.getOutputs(); assert(result === ["10u32"]); ``` ### Response #### Success Response (200) None (Client-side JavaScript example) #### Response Example None (Client-side JavaScript example) ``` -------------------------------- ### Import Testnet Network Module Source: https://docs.explorer.provable.com/docs/sdk/iv67tt1dqrsli-setup Imports necessary classes and functions from the Provable SDK specifically for the testnet network. This is the default network if none is explicitly selected. ```javascript import { Account, ProgramManager, initThreadPool } from '@provablehq/sdk/testnet.js'; ``` -------------------------------- ### Import Default (Testnet) Network Module Source: https://docs.explorer.provable.com/docs/sdk/iv67tt1dqrsli-setup Imports necessary classes and functions from the Provable SDK without explicitly selecting a network, defaulting to the testnet. Use this if testnet is your intended network. ```javascript import { Account, ProgramManager, initThreadPool } from '@provablehq/sdk'; ``` -------------------------------- ### Initialize Multithreaded WebAssembly Source: https://docs.explorer.provable.com/docs/sdk/iv67tt1dqrsli-setup Initializes multithreaded WebAssembly for improved performance by calling `initThreadPool`. This should be called once at the beginning of your application before other SDK functions. ```javascript 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... ``` -------------------------------- ### Configure Webpack for Top-Level Await Source: https://docs.explorer.provable.com/docs/sdk/iv67tt1dqrsli-setup Enables `topLevelAwait` and `asyncWebAssembly` in webpack configuration, which are required for the Provable SDK to function correctly. ```javascript experiments: { asyncWebAssembly: true, topLevelAwait: true, } ``` -------------------------------- ### Execute Private Transfer on Aleo with Provable SDK (JavaScript) Source: https://docs.explorer.provable.com/docs/sdk/k4fqfewyw3lgb-transfer-private This JavaScript code snippet demonstrates how to perform a private transfer on the Aleo network. It includes initializing the SDK, creating accounts, setting up network clients, and building/broadcasting both public-to-private and private transfer transactions. Ensure you have the necessary SDK dependencies installed. ```javascript import { Account, ProgramManager, initThreadPool } from '@provable/sdk'; import { AleoNetworkClient, AleoKeyProvider, NetworkRecordProvider } from '@provable/sdk/dist/lib/aleo'; // Initialize multi-threading to allow WASM execution. await initThreadPool(); // 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.explorer.provable.com/v1"); 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.explorer.provable.com/v1", 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.1, // The 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.1, // The 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); ``` -------------------------------- ### Example: Cache and Retrieve Function Keys Source: https://docs.explorer.provable.com/docs/sdk/d337942f8c449-offline-key-provider This example demonstrates the process of caching keys from local offline resources using `OfflineKeyProvider` and then retrieving them later using `functionKeys`. It involves reading proving key bytes, creating key objects, caching them with a locator, and then using search parameters to retrieve the cached keys. ```javascript /// First cache the keys from local offline resources const offlineKeyProvider = new OfflineKeyProvider(); const myFunctionVerifyingKey = VerifyingKey.fromString("verifier..."); const myFunctionProvingKeyBytes = await readBinaryFile('./resources/myfunction.prover'); const myFunctionProvingKey = ProvingKey.fromBytes(myFunctionProvingKeyBytes); /// Cache the keys for future use with a memorable locator offlineKeyProvider.cacheKeys("myprogram.aleo/myfunction", [myFunctionProvingKey, myFunctionVerifyingKey]); /// When they're needed, retrieve the keys from the cache /// First create a search parameter object with the same locator used to cache the keys const keyParams = new OfflineSearchParams("myprogram.aleo/myfunction"); /// Then retrieve the keys const [myFunctionProver, myFunctionVerifier] = await offlineKeyProvider.functionKeys(keyParams); ``` -------------------------------- ### Program Execution Example Source: https://docs.explorer.provable.com/docs/sdk/27aaf4eb69363-program-manger Demonstrates how to execute a simple Aleo program ('helloworld') using the ProgramManager. ```APIDOC ## Program Execution Example ### Description This example shows how to compile and run a basic Aleo program named 'helloworld' which adds two numbers. It covers setting up an account, compiling the program, and executing the 'hello' function with sample inputs. ### Method N/A (Illustrative code) ### Endpoint N/A (Client-side SDK) ### Parameters N/A ### Request Example ```javascript import { Account, Program } from '@provablehq/sdk'; /// Create the source for the "helloworld" program 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;"; const programManager = new ProgramManager(); /// Create a temporary account for the execution of the program const account = new Account(); programManager.setAccount(account); /// Get the response and ensure that the program executed correctly const executionResponse = await programManager.run(program, "hello", ["5u32", "5u32"]); const result = executionResponse.getOutputs(); assert(result === ["10u32"]); ``` ### Response #### Success Response (200) - **result** (Array) - The output(s) of the program execution. ``` -------------------------------- ### Split Credits Example Source: https://docs.explorer.provable.com/docs/sdk/642b6790602a0-wasm Example of how to use the `split` function to divide credits into two new records. ```APIDOC ## Split Credits Example ### Description This example demonstrates how to use the `split` function to divide a given credits record into two new records. It involves setting up network clients and providers, initializing a program manager, and then calling the `split` function with the desired amount and record. ### Method Not applicable (Client-side JavaScript example) ### Endpoint Not applicable (Client-side JavaScript example) ### Parameters None (Client-side JavaScript example) ### Request Example ```javascript // Create a new NetworkClient, KeyProvider, and RecordProvider const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); 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 programName = "hello_hello.aleo"; const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); const record = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"; const tx_id = await programManager.split(25000000, record); const transaction = await programManager.networkClient.getTransaction(tx_id); ``` ### Response #### Success Response (200) None (Client-side JavaScript example) #### Response Example None (Client-side JavaScript example) ``` -------------------------------- ### Account from Ciphertext Example (JavaScript) Source: https://docs.explorer.provable.com/docs/sdk/0qgi3uyhotv62-account Shows how to create an Aleo account from an encrypted private key (ciphertext) using a password. ```javascript const ciphertext = PrivateKey.newEncrypted("password"); const account = Account.fromCiphertext(ciphertext, "password"); ``` -------------------------------- ### Set and Get Account for Network Client Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Provides examples for setting and retrieving the Aleo account associated with the `AleoNetworkClient`. This account is used for network client calls that require authentication or signing. ```javascript const account = new Account(); networkClient.setAccount(account); const currentAccount = networkClient.getAccount(); ``` -------------------------------- ### Get Aleo Credits Program Instance Source: https://docs.explorer.provable.com/docs/sdk/642b6790602a0-wasm This snippet shows how to obtain an instance of the Aleo Credits program. This is a foundational step for interacting with any of its associated functions or data structures. ```javascript const credits_program = aleo_wasm.Program.getCreditsProgram(); ``` -------------------------------- ### Sign Message Example (JavaScript) Source: https://docs.explorer.provable.com/docs/sdk/0qgi3uyhotv62-account Demonstrates how to sign an arbitrary message (as a Uint8Array) using an Aleo account's private key, producing a valid signature. ```javascript const account = new Account(); const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100]) account.sign(message); ``` -------------------------------- ### Verify Signature Example (JavaScript) Source: https://docs.explorer.provable.com/docs/sdk/0qgi3uyhotv62-account Shows how to verify if a given signature is valid for a specific message using an Aleo account. ```javascript const account = new Account(); const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100]) const signature = account.sign(message); account.verify(message, signature); ``` -------------------------------- ### OfflineKeyProvider Class Usage Source: https://docs.explorer.provable.com/docs/sdk/d337942f8c449-offline-key-provider Example of how to instantiate and use the OfflineKeyProvider to manage cryptographic keys, including caching transfer public keys. ```APIDOC ## OfflineKeyProvider Class ### Description The `OfflineKeyProvider` class provides methods for managing cryptographic proving and verifying keys within the Aleo SDK. It allows you to cache keys for specific functions, which can then be retrieved for use in cryptographic operations. ### Initialization ```javascript // Create a new OfflineKeyProvider const offlineKeyProvider = new OfflineKeyProvider(); ``` ### Caching Transfer Public Keys This example demonstrates how to load and cache the proving key for the `transfer_public` function. ```javascript // Load the transfer public proving key from a file const transferPublicProvingKeyBytes = await readBinaryFile('./resources/transfer_public.prover.a74565e'); const transferPublicProvingKey = ProvingKey.fromBytes(transferPublicProvingKeyBytes); // Cache the transfer_public keys for future use with the OfflinKeyProvider's convenience method // The verifying key will be cached automatically. offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey); ``` ### Retrieving Cached Keys After keys have been cached, they can be retrieved using the `keyProvider` (assumed to be an instance of `OfflineKeyProvider` or a compatible interface). ```javascript // Retrieve the transfer_public keys from the cache const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public"); ``` ``` -------------------------------- ### Encrypt Account Private Key Example (JavaScript) Source: https://docs.explorer.provable.com/docs/sdk/0qgi3uyhotv62-account Demonstrates encrypting an Aleo account's private key using a password, generating a PrivateKeyCiphertext. ```javascript const account = new Account(); const ciphertext = account.encryptAccount("password"); ``` -------------------------------- ### Aleo Account Creation and Usage Examples (JavaScript) Source: https://docs.explorer.provable.com/docs/sdk/0qgi3uyhotv62-account Demonstrates creating new Aleo accounts, importing existing ones from seeds or private keys, signing messages, and verifying signatures using the Account class. ```javascript // Create a new account const myRandomAccount = new Account(); // Create an account from a randomly generated seed const seed = new Uint8Array([94, 91, 52, 251, 240, 230, 226, 35, 117, 253, 224, 210, 175, 13, 205, 120, 155, 214, 7, 169, 66, 62, 206, 50, 188, 40, 29, 122, 40, 250, 54, 18]); const mySeededAccount = new Account({seed: seed}); // Create an account from an existing private key const myExistingAccount = new Account({privateKey: 'myExistingPrivateKey'}) // Sign a message const hello_world = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100]) const signature = myRandomAccount.sign(hello_world) // Verify a signature myRandomAccount.verify(hello_world, signature) ``` -------------------------------- ### Get Block Range using Network Client Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Fetches a range of blocks from the network client. Requires the start and end block numbers as input. ```javascript const blockRange = networkClient.getBlockRange(2050, 2100); ``` -------------------------------- ### OfflineKeyProvider Usage Example Source: https://docs.explorer.provable.com/docs/sdk/d337942f8c449-offline-key-provider Demonstrates how to set up and use the OfflineKeyProvider for offline transaction building. This includes creating a ProgramManager, Account, loading key files, caching keys, creating an OfflineQuery and OfflineSearchParams, and finally building and broadcasting an execution transaction. ```typescript 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.explorer.provable.com/v1"); const txId = await networkClient.broadcastTransaction(offlineExecuteTx); ``` -------------------------------- ### Execute Aleo Program 'hello' Source: https://docs.explorer.provable.com/docs/sdk/27aaf4eb69363-program-manger Demonstrates how to define, deploy, and execute an Aleo program named 'helloworld'. It includes creating a temporary account, setting up a program manager, and running the 'hello' function with specified inputs. The response is then asserted to ensure correct execution. ```typescript import { Account, Program } from '@provablehq/sdk'; /// Create the source for the "helloworld" program 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;"; const programManager = new ProgramManager(); /// Create a temporary account for the execution of the program const account = new Account(); programManager.setAccount(account); /// Get the response and ensure that the program executed correctly const executionResponse = await programManager.run(program, "hello", ["5u32", "5u32"]); const result = executionResponse.getOutputs(); assert(result === ["10u32"]); ``` -------------------------------- ### Deploy Aleo Program with ProgramManager Source: https://docs.explorer.provable.com/docs/sdk/27aaf4eb69363-program-manger This example shows how to deploy an Aleo program to the network. It involves setting up NetworkClient, KeyProvider, and RecordProvider, then initializing a ProgramManager and calling the deploy method with program source code and fee details. ```javascript // Create a new NetworkClient, KeyProvider, and RecordProvider const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // 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.explorer.provable.com/v1", keyProvider, recordProvider); // Define a fee in credits const fee = 1.2; // Create the deployment transaction. const tx = await programManager.buildDeploymentTransaction(program, fee, false); ``` -------------------------------- ### Deploy Leo Program on Aleo Source: https://docs.explorer.provable.com/docs/sdk/4jyvalinn1n0i-program-deployment This JavaScript snippet shows how to deploy a Leo program to the Aleo network. It involves initializing the SDK, creating an account, setting up network clients, building a deployment transaction, and submitting it to the network. Dependencies include '@provablehq/sdk'. ```javascript import { Account, ProgramManager, initThreadPool } from '@provablehq/sdk'; import { AleoNetworkClient, AleoKeyProvider, NetworkRecordProvider } from '@provablehq/sdk/aleo'; // Initialize multi-threading to allow WASM execution. await initThreadPool(); // 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.explorer.provable.com/v1"); 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.explorer.provable.com/v1", keyProvider, recordProvider); // Set the account as the program caller. programManager.setAccount(account); // Declare program source code using Aleo Instructions const program = ` program addition_demo.aleo; function addition: input r0 as u32.public; input r1 as u32.public; add r0 r1 into r2; output r2 as u32.public; `; // Create a deployment transaction using the declared source code. const transaction = await programManager.buildDeploymentTransaction(program, 3, false); // Broadcast the transaction to the Aleo network. const result = await programManager.networkClient.submitTransaction(transaction); ``` -------------------------------- ### Initialize and Cache Keys with OfflineKeyProvider Source: https://docs.explorer.provable.com/docs/sdk/d337942f8c449-offline-key-provider Demonstrates how to create a new OfflineKeyProvider, read and cache transfer public proving keys, and then retrieve both proving and verifying keys when needed. This process involves initializing the provider, loading keys from a file, and inserting them for later use. ```javascript const offlineKeyProvider = new OfflineKeyProvider(); const transferPublicProvingKeyBytes = await readBinaryFile('./resources/transfer_public.prover.a74565e'); const transferPublicProvingKey = ProvingKey.fromBytes(transferPublicProvingKeyBytes); offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey); const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public"); ``` -------------------------------- ### Check Record Ownership Example (JavaScript) Source: https://docs.explorer.provable.com/docs/sdk/0qgi3uyhotv62-account Provides an example of checking if an Aleo account owns a specific record ciphertext, often used before attempting decryption or further processing. ```javascript // Create a connection to the Aleo network and an account const connection = new AleoNetworkClient("https://api.explorer.provable.com/v1"); const account = Account.fromCiphertext(process.env.ciphertext, process.env.password); // Get a record from the network const record = connection.getBlock(1234); const recordCipherText = record.transactions[0].execution.transitions[0].id; // Check if the account owns the record if account.ownsRecord(recordCipherText) { // Then one can do something like: // Decrypt the record and check if it's spent // Store the record in a local database // Etc. } ``` -------------------------------- ### Deploy Aleo Program with Provable SDK (JavaScript) Source: https://docs.explorer.provable.com/docs/sdk/xok59aee04h1w-deploying-programs This snippet demonstrates how to deploy an Aleo program using the Provable SDK in a JavaScript/TypeScript environment. It covers setting up key and record providers, initializing an account, and using the ProgramManager to build and submit a deployment transaction. Ensure you have the necessary private key and sufficient Aleo credits for the fee. ```javascript import { Account, AleoNetworkClient, NetworkRecordProvider, ProgramManager, AleoKeyProvider} from '@provablehq/sdk/testnet.js'; // Create a key provider that will be used to find public proving & verifying keys for Aleo programs const keyProvider = new AleoKeyProvider(); 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"); // Use existing account with funds const account = new Account({ privateKey: env.var("PRIVATE_KEY"), }); // 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", keyProvider); programManager.setAccount(account) // Define an Aleo program to deploy 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"; // Define a fee to pay to deploy the program const fee = 3.8; // 3.8 Aleo credits // Build a deployment transaction for the program. const tx = await programManager.buildDeploymentTransaction(program, fee, false); // Send the transaction to the network. const tx_id = await programManager.networkClient.submitTransaction(tx); // Verify the transaction was successful const transaction = await programManager.networkClient.getTransaction(tx_id); ``` -------------------------------- ### Key Provider API - Get Verifying Key Source: https://docs.explorer.provable.com/docs/sdk/713c66164f390-function-key-provider Gets a verifying key. If the verifying key is for a credits.aleo function, it is retrieved from the WASM cache; otherwise, it's fetched from the network. ```APIDOC ## GET /getVerifyingKey ### Description Gets a verifying key. If the verifying key is for a credits.aleo function, get it from the wasm cache otherwise. ### Method GET ### Endpoint /getVerifyingKey ### Parameters #### Query Parameters - **programId** (string) - Required - The ID of the program for which to get the verifying key. - **functionName** (string) - Required - The name of the function for which to get the verifying key. ### Request Example ```json { "programId": "credits.aleo", "functionName": "transfer_public" } ``` ### Response #### Success Response (200) - **verifyingKey** (string) - The verifying key for the specified function. #### Response Example ```json { "verifyingKey": "..." } ``` ``` -------------------------------- ### Deploy Program Source: https://docs.explorer.provable.com/docs/sdk/642b6790602a0-wasm Deploys an Aleo program to the network. Requires a program string, fee, and optionally a flag for private fee. ```APIDOC ## POST /deploy ### Description Deploys an Aleo program to the network. This function takes the program source code, a fee in credits, and a boolean indicating if the fee should be private. ### Method POST ### Endpoint /deploy ### Parameters #### Request Body - **program** (string) - Required - The Aleo program source code. - **fee** (number) - Required - The fee in credits for the deployment. - **privateFee** (boolean) - Optional - If true, the fee will be private. ### Request Example ```json { "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;", "fee": 1.2, "privateFee": false } ``` ### Response #### Success Response (200) - **tx_id** (string) - The transaction ID of the deployment. #### Response Example ```json { "tx_id": "tx123abc..." } ``` ``` -------------------------------- ### Deploy Aleo Program using ProgramManager Source: https://docs.explorer.provable.com/docs/sdk/27aaf4eb69363-program-manger This snippet shows how to deploy an Aleo program. It initializes necessary clients and managers, defines the program source code and deployment fee, and then initiates the deployment. The transaction ID is returned upon successful deployment. Dependencies include AleoNetworkClient, AleoKeyProvider, NetworkRecordProvider, and ProgramManager. ```javascript // Create a new NetworkClient, KeyProvider, and RecordProvider const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // 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.explorer.provable.com/v1", keyProvider, recordProvider); // Define a fee in credits const fee = 1.2; // Deploy the program const tx_id = await programManager.deploy(program, fee, false); // Verify the transaction was successful const transaction = await programManager.networkClient.getTransaction(tx_id); ``` -------------------------------- ### GET /transactions Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Retrieves all transactions at a specified block height. ```APIDOC ## GET /transactions ### Description Returns the transactions present at the specified block height. ### Method GET ### Endpoint /transactions ### Parameters #### Query Parameters - **height** (number) - Required - The block height to retrieve transactions from. ### Request Example ```json { "height": 654 } ``` ### Response #### Success Response (200) - **transactions** (Array) - A list of transactions at the specified height. #### Response Example ```json { "transactions": [ { "id": "tx_123", "from": "aleo1abc...", "to": "aleo1def...", "amount": 10000 } ] } ``` ``` -------------------------------- ### Get Proving Key Checksum Source: https://docs.explorer.provable.com/docs/sdk/642b6790602a0-wasm Retrieves the checksum of a proving key. This is useful for verifying the integrity of the key. ```javascript // Assuming 'provingKey' is an instance of ProvingKey const checksum = provingKey.checksum(); console.log(checksum); ``` -------------------------------- ### GET /getTransactions Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Retrieves all transactions that occurred at a specified block height. ```APIDOC ## GET /getTransactions ### Description Returns the transactions present at the specified block height. ### Method GET ### Endpoint /getTransactions ### Parameters #### Query Parameters - **height** (number) - Required - The block height to retrieve transactions from. ### Response #### Success Response (200) - **return** (Promise.>) - An array of confirmed transactions at the specified height. #### Response Example ```json { "example": "const transactions = networkClient.getTransactions(654);" } ``` ``` -------------------------------- ### Create Aleo Account from Existing Private Key Source: https://docs.explorer.provable.com/docs/sdk/ghweubjq0or1x-creating-accounts Demonstrates creating an Aleo account using an existing private key, either newly generated, from a string representation, or directly from a private key string, utilizing the `Account` class and `PrivateKey` from `@provablehq/sdk`. ```typescript import { Account } from '@provablehq/sdk'; import { PrivateKey } from './wasm'; // From a newly generated private key const privateKey = new PrivateKey(); const account = new Account({ privateKey }); // From a private key derived from its string representation const privateKey2 = PrivateKey.fromString('APrivateKey1...'); const account2 = new Account({ privateKey: privateKey2, }); // From a private key string const account3 = new Account({ privateKey: 'APrivateKey1...', }); ``` -------------------------------- ### GET /getTransaction Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Retrieves a transaction from the blockchain using its unique identifier. ```APIDOC ## GET /getTransaction ### Description Returns a transaction by its unique identifier. ### Method GET ### Endpoint /getTransaction ### Parameters #### Query Parameters - **id** (string) - Required - The unique identifier of the transaction. ### Response #### Success Response (200) - **return** (Promise.) - The transaction details. #### Response Example ```json { "example": "const transaction = networkClient.getTransaction(\"at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj\");" } ``` ``` -------------------------------- ### Fetch Public Transfer Keys Source: https://docs.explorer.provable.com/docs/sdk/713c66164f390-function-key-provider Illustrates initializing the Aleo network components and program manager, similar to the private transfer example. It specifically shows how to manually fetch the proving and verifying keys for public transfers. ```javascript // Create a new AleoKeyProvider const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); 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.explorer.provable.com/v1", keyProvider, recordProvider); programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); // Keys can also be fetched manually const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public"); ``` -------------------------------- ### GET /raw Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Fetches raw data from the Aleo network as an unparsed string. ```APIDOC ## GET /raw ### Description Fetches data from the Aleo network and returns it as an unparsed string. This method should be used when it is desired to reconstitute data returned from the network into a WASM object. ### Method GET ### Endpoint /raw ### Parameters #### Query Parameters - **url** (string) - Required - The URL to fetch raw data from. ### Request Example (No request body needed) ### Response #### Success Response (200) - **rawData** (string) - The raw, unparsed string data. #### Response Example ```json { "rawData": "binary_data_string" } ``` ``` -------------------------------- ### POST /submit/solution Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Submits a solution to the Aleo network. ```APIDOC ## POST /submit/solution ### Description Submit a solution to the Aleo network. ### Method POST ### Endpoint /submit/solution ### Parameters #### Request Body - **solution** (string) - Required - The string representation of the solution desired to be submitted to the network. ### Request Example ```json { "solution": "solution_string_here" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message of successful submission. #### Response Example ```json { "message": "Solution submitted successfully." } ``` ``` -------------------------------- ### GET /data Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Fetches data from the Aleo network and returns it as a JSON object. ```APIDOC ## GET /data ### Description Fetches data from the Aleo network and returns it as a JSON object. ### Method GET ### Endpoint /data ### Parameters #### Query Parameters - **url** (string) - Required - The URL to fetch data from. ### Request Example (No request body needed) ### Response #### Success Response (200) - **data** (object) - The JSON object containing the fetched data. #### Response Example ```json { "data": { "key": "value" } } ``` ``` -------------------------------- ### Get Record Tag Source: https://docs.explorer.provable.com/docs/sdk/642b6790602a0-wasm Calculates the tag of a record using the provided GraphKey and commitment. The tag is a cryptographic identifier for the record. ```javascript // Assuming 'recordCiphertext' is an instance of RecordCiphertext, 'graphKey' is a GraphKey, and 'commitment' is a Field const tag = recordCiphertext.tag(graphKey, commitment); ``` -------------------------------- ### Program Deployment Source: https://docs.explorer.provable.com/docs/sdk/642b6790602a0-wasm Deploys an Aleo program to the network. This involves creating a transaction, signing it, and submitting it. ```APIDOC ## POST /websites/explorer_provable/deploy ### Description Deploys an Aleo program to the network. This involves creating a transaction, signing it, and submitting it. ### Method POST ### Endpoint /websites/explorer_provable/deploy ### Parameters #### Request Body - **program** (string) - Required - The Aleo program source code to deploy. - **fee** (number) - Required - The fee in credits for deploying the program. - **privateFee** (boolean) - Optional - Whether to use a private fee. ### Request Example ```json { "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;", "fee": 1.2, "privateFee": false } ``` ### Response #### Success Response (200) - **tx_id** (string) - The transaction ID of the deployment. #### Response Example ```json { "tx_id": "tx123abc456def" } ``` ``` -------------------------------- ### GET /getTransitionId Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Retrieves the transition ID associated with a given input or output ID. ```APIDOC ## GET /getTransitionId ### Description Returns the transition ID of the transition corresponding to the ID of the input or output. ### Method GET ### Endpoint /getTransitionId ### Parameters #### Query Parameters - **inputOrOutputID** (string) - Required - ID of the input or output. ### Response #### Success Response (200) - **return** (Promise.) - The transition ID. #### Response Example ```json { "example": "const transitionId = networkClient.getTransitionId(\"2429232855236830926144356377868449890830704336664550203176918782554219952323field\");" } ``` ``` -------------------------------- ### ProgramManager - deploy() Source: https://docs.explorer.provable.com/docs/sdk/642b6790602a0-wasm Deploys an Aleo program to the Aleo network. ```APIDOC ## ProgramManager - deploy() ### Description Deploys an Aleo program to the Aleo network. This method handles the entire process from building the transaction to submitting it. ### Method `deploy(program, fee, privateFee, recordSearchParams, feeRecord, privateKey)` ### Endpoint N/A (Method within a ProgramManager object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **program** (string) - Required - Program source code to deploy. - **fee** (number) - Required - Fee to pay for the transaction. - **privateFee** (boolean) - Required - Use a private record to pay the fee. If false, uses the account's public credit balance. - **recordSearchParams** (RecordSearchParams) - Optional - Parameters for searching for a record to use to pay the deployment fee. - **feeRecord** (string) - Optional - Fee record to use for the transaction. - **privateKey** (PrivateKey) - Optional - Private key to use for the transaction. ### Request Example ```javascript // Assuming NetworkClient, AleoKeyProvider, NetworkRecordProvider, and ProgramManager are initialized const programSource = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;"; const fee = 1.2; const tx = await programManager.deploy(programSource, fee, false); console.log(tx); // Output: Transaction ID or failure message ``` ### Response #### Success Response (200) - **return** (string) - The transaction id of the deployed program or a failure message from the network. ``` -------------------------------- ### GET /getStateRoot Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Retrieves the latest state root (Merkle root) of the Aleo blockchain. ```APIDOC ## GET /getStateRoot ### Description Returns the latest state/merkle root of the Aleo blockchain. ### Method GET ### Endpoint /getStateRoot ### Response #### Success Response (200) - **return** (Promise.) - The latest state root of the Aleo blockchain. #### Response Example ```json { "example": "const stateRoot = networkClient.getStateRoot();" } ``` ``` -------------------------------- ### Build Deployment Transaction Source: https://docs.explorer.provable.com/docs/sdk/642b6790602a0-wasm This example shows how to build a deployment transaction for an Aleo program. It involves setting up a network client, key provider, and record provider, then initializing a program manager and calling the buildDeploymentTransaction method with program source code and fee details. ```javascript // Create a new NetworkClient, KeyProvider, and RecordProvider const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // 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.explorer.provable.com/v1", keyProvider, recordProvider); // Define a fee in credits const fee = 1.2; // Create the deployment transaction. const tx = await programManager.buildDeploymentTransaction(program, fee, false); ``` -------------------------------- ### GET /account Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Retrieves the currently set Aleo account used by the network client. ```APIDOC ## GET /account ### Description Return the Aleo account used in the networkClient. ### Method GET ### Endpoint /account ### Parameters None ### Request Example (No request body needed) ### Response #### Success Response (200) - **account** (Account) - The current account object. #### Response Example ```json { "account": { "privateKey": "PrivateKey_....", "address": "aleo1abc..." } } ``` ``` -------------------------------- ### Create and Use Program Manager for Transfers Source: https://docs.explorer.provable.com/docs/sdk/713c66164f390-function-key-provider Demonstrates creating Aleo network clients, key providers, and record providers to initialize a program manager. It shows how to automatically fetch keys for value transfers and manually fetch keys for private transfers. ```javascript // Create a new AleoKeyProvider object const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); 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.explorer.provable.com/v1", keyProvider, recordProvider); programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); // Keys can also be fetched manually const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.fetchKeys( CREDITS_PROGRAM_KEYS.transfer_private.prover, CREDITS_PROGRAM_KEYS.transfer_private.verifier, ); ``` -------------------------------- ### GET /transition/:inputOrOutputID Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Retrieves the transition ID associated with a given input or output ID. ```APIDOC ## GET /transition/:inputOrOutputID ### Description Returns the transition ID of the transition corresponding to the ID of the input or output. ### Method GET ### Endpoint /transition/:inputOrOutputID ### Parameters #### Path Parameters - **inputOrOutputID** (string) - Required - The ID of the input or output. ### Request Example (No request body needed) ### Response #### Success Response (200) - **transitionId** (string) - The transition ID. #### Response Example ```json { "transitionId": "tx_transition_789" } ``` ``` -------------------------------- ### Get Transaction by ID Source: https://docs.explorer.provable.com/docs/sdk/c592747bdee96-network-client Retrieves a transaction from the Aleo network using its unique transaction ID. ```APIDOC ## GET /websites/explorer_provable/transactions/{id} ### Description Fetches a specific transaction from the Aleo network based on its unique identifier. ### Method GET ### Endpoint `/websites/explorer_provable/transactions/{id}` ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the transaction to retrieve (e.g., "at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj"). ### Request Example ```javascript const transaction = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj"); ``` ### Response #### Success Response (200) - **transaction** (object) - An object representing the transaction details. #### Response Example ```json { "id": "at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj", "...": "..." } ``` ```