UNPKG

@provablehq/sdk

Version:

A Software Development Kit (SDK) for Zero-Knowledge Transactions

774 lines (773 loc) 37.9 kB
import { Account } from "./account.js"; import { BlockJSON } from "./models/blockJSON.js"; import { TransactionJSON } from "./models/transaction/transactionJSON.js"; import { Address, Plaintext, Program, ProvingRequest, RecordPlaintext, PrivateKey, Transaction } from "./wasm.js"; import { ConfirmedTransactionJSON } from "./models/confirmed_transaction.js"; import { ProvingResponse } from "./models/provingResponse.js"; type ProgramImports = { [key: string]: string | Program; }; interface AleoNetworkClientOptions { headers?: { [key: string]: string; }; } /** * Options for submitting a proving request. * * @property provingRequest {ProvingRequest | string} The proving request being submitted to the network. * @property url {string} The URL of the delegated proving service. * @property apiKey {string} The API key to use for authentication. */ interface DelegatedProvingParams { provingRequest: ProvingRequest | string; url?: string; apiKey?: string; } /** * Client library that encapsulates REST calls to publicly exposed endpoints of Aleo nodes. The methods provided in this * allow users to query public information from the Aleo blockchain and submit transactions to the network. * * @param {string} host * @example * // Connection to a local node. * const localNetworkClient = new AleoNetworkClient("http://0.0.0.0:3030", undefined, account); * * // Connection to a public beacon node * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password); * const publicNetworkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined, account); */ declare class AleoNetworkClient { host: string; headers: { [key: string]: string; }; account: Account | undefined; ctx: { [key: string]: string; }; verboseErrors: boolean; readonly network: string; constructor(host: string, options?: AleoNetworkClientOptions); /** * Set an account to use in networkClient calls * * @param {Account} account Set an account to use for record scanning functions. * @example * import { Account, AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1"); * const account = new Account(); * networkClient.setAccount(account); */ setAccount(account: Account): void; /** * Return the Aleo account used in the networkClient * * @example * const account = networkClient.getAccount(); */ getAccount(): Account | undefined; /** * Set a new host for the networkClient * * @param {string} host The address of a node hosting the Aleo API * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a networkClient that connects to a local node. * const networkClient = new AleoNetworkClient("http://0.0.0.0:3030", undefined); * * // Set the host to a public node. * networkClient.setHost("http://api.explorer.provable.com/v1"); */ setHost(host: string): void; /** * Set verbose errors to true or false for the `AleoNetworkClient`. When set to true, if `submitTransaction` fails, the failure responses will report descriptive information as to why the transaction failed. * * @param {boolean} verboseErrors Set verbose error mode to true or false for the AleoNetworkClient. * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a networkClient * const networkClient = new AleoNetworkClient(); * * // Set debug mode to true * networkClient.setVerboseTransactionErrors(true); **/ setVerboseErrors(verboseErrors: boolean): void; /** * Set a header in the `AleoNetworkClient`s header map * * @param {string} headerName The name of the header to set * @param {string} value The header value * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a networkClient * const networkClient = new AleoNetworkClient(); * * // Set the value of the `Accept-Language` header to `en-US` * networkClient.setHeader('Accept-Language', 'en-US'); */ setHeader(headerName: string, value: string): void; removeHeader(headerName: string): void; /** * Fetches data from the Aleo network and returns it as a JSON object. * * @param url The URL to fetch data from. */ fetchData<Type>(url?: string): Promise<Type>; /** * 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. * * @param url */ fetchRaw(url?: string): Promise<string>; /** * Wrapper around the POST helper to allow mocking in tests. Not meant for use in production. * * @param url The URL to POST to. * @param options The RequestInit options for the POST request. * @returns The Response object from the POST request. */ private _sendPost; /** * Attempt to find records in the Aleo blockchain. * * @param {number} startHeight - The height at which to start searching for unspent records * @param {number} endHeight - The height at which to stop searching for unspent records * @param {boolean} unspent - Whether to search for unspent records only * @param {string[]} programs - The program(s) to search for unspent records in * @param {number[]} amounts - The amounts (in microcredits) to search for (eg. [100, 200, 3000]) * @param {number} maxMicrocredits - The maximum number of microcredits to search for * @param {string[]} nonces - The nonces of already found records to exclude from the search * @param {string | PrivateKey} privateKey - An optional private key to use to find unspent records. * @returns {Promise<Array<RecordPlaintext>>} An array of records belonging to the account configured in the network client. * * @example * import { Account, AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Import an account from a ciphertext and password. * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password); * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * networkClient.setAccount(account); * * // Find specific amounts * const startHeight = 500000; * const amounts = [600000, 1000000]; * const records = networkClient.findRecords(startHeight, undefined, true, ["credits.aleo"] amounts); * * // Find specific amounts with a maximum number of cumulative microcredits * const maxMicrocredits = 100000; * const records = networkClient.findRecords(startHeight, undefined, true, ["credits.aleo"] undefined, maxMicrocredits); */ findRecords(startHeight: number, endHeight: number | undefined, unspent?: boolean, programs?: string[], amounts?: number[] | undefined, maxMicrocredits?: number | undefined, nonces?: string[] | undefined, privateKey?: string | PrivateKey | undefined): Promise<Array<RecordPlaintext>>; /** * Attempts to find unspent records in the Aleo blockchain. * * @param {number} startHeight - The height at which to start searching for unspent records * @param {number} endHeight - The height at which to stop searching for unspent records * @param {string[]} programs - The program(s) to search for unspent records in * @param {number[]} amounts - The amounts (in microcredits) to search for (eg. [100, 200, 3000]) * @param {number} maxMicrocredits - The maximum number of microcredits to search for * @param {string[]} nonces - The nonces of already found records to exclude from the search * @param {string | PrivateKey} privateKey - An optional private key to use to find unspent records. * @returns {Promise<Array<RecordPlaintext>>} An array of unspent records belonging to the account configured in the network client. * * @example * import { Account, AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password); * * // Create a network client and set an account to search for records with. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * networkClient.setAccount(account); * * // Find specific amounts * const startHeight = 500000; * const endHeight = 550000; * const amounts = [600000, 1000000]; * const records = networkClient.findUnspentRecords(startHeight, endHeight, ["credits.aleo"], amounts); * * // Find specific amounts with a maximum number of cumulative microcredits * const maxMicrocredits = 100000; * const records = networkClient.findUnspentRecords(startHeight, undefined, ["credits.aleo"], undefined, maxMicrocredits); */ findUnspentRecords(startHeight: number, endHeight: number | undefined, programs?: string[], amounts?: number[] | undefined, maxMicrocredits?: number | undefined, nonces?: string[] | undefined, privateKey?: string | PrivateKey | undefined): Promise<Array<RecordPlaintext>>; /** * Returns the contents of the block at the specified block height. * * @param {number} blockHeight - The height of the block to fetch * @returns {Promise<BlockJSON>} A javascript object containing the block at the specified height * * @example * const block = networkClient.getBlock(1234); */ getBlock(blockHeight: number): Promise<BlockJSON>; /** * Returns the contents of the block with the specified hash. * * @param {string} blockHash The hash of the block to fetch. * @returns {Promise<BlockJSON>} A javascript object representation of the block matching the hash. * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * const block = networkClient.getBlockByHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9"); */ getBlockByHash(blockHash: string): Promise<BlockJSON>; /** * Returns a range of blocks between the specified block heights. A maximum of 50 blocks can be fetched at a time. * * @param {number} start Starting block to fetch. * @param {number} end Ending block to fetch. This cannot be more than 50 blocks ahead of the start block. * @returns {Promise<Array<BlockJSON>>} An array of block objects * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Fetch 50 blocks. * const (start, end) = (2050, 2100); * const blockRange = networkClient.getBlockRange(start, end); * * let cursor = start; * blockRange.forEach((block) => { * assert(block.height == cursor); * cursor += 1; * } */ getBlockRange(start: number, end: number): Promise<Array<BlockJSON>>; /** * Returns the deployment transaction id associated with the specified program. * * @param {Program | string} program The name of the deployed program OR a wasm Program object. * @returns {Promise<string>} The transaction ID of the deployment transaction. * * @example * import { AleoNetworkClient } from "@provablehq/sdk/testnet.js"; * * // Get the transaction ID of the deployment transaction for a program. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo"); * * // Get the transaction data for the deployment transaction. * const transaction = networkClient.getTransactionObject(transactionId); * * // Get the verifying keys for the functions in the deployed program. * const verifyingKeys = transaction.verifyingKeys(); */ getDeploymentTransactionIDForProgram(program: Program | string): Promise<string>; /** * Returns the deployment transaction associated with a specified program as a JSON object. * * @param {Program | string} program The name of the deployed program OR a wasm Program object. * @returns {Promise<Transaction>} JSON representation of the deployment transaction. * * @example * import { AleoNetworkClient, DeploymentJSON } from "@provablehq/sdk/testnet.js"; * * // Get the transaction ID of the deployment transaction for a program. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * const transaction = networkClient.getDeploymentTransactionForProgram("hello_hello.aleo"); * * // Get the verifying keys for each function in the deployment. * const deployment = <DeploymentJSON>transaction.deployment; * const verifyingKeys = deployment.verifying_keys; */ getDeploymentTransactionForProgram(program: Program | string): Promise<TransactionJSON>; /** * Returns the deployment transaction associated with a specified program as a wasm object. * * @param {Program | string} program The name of the deployed program OR a wasm Program object. * @returns {Promise<Transaction>} Wasm object representation of the deployment transaction. * * @example * import { AleoNetworkClient } from "@provablehq/sdk/testnet.js"; * * // Get the transaction ID of the deployment transaction for a program. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * const transactionId = networkClient.getDeploymentTransactionIDForProgram("hello_hello.aleo"); * * // Get the transaction data for the deployment transaction. * const transaction = networkClient.getDeploymentTransactionObjectForProgram(transactionId); * * // Get the verifying keys for the functions in the deployed program. * const verifyingKeys = transaction.verifyingKeys(); */ getDeploymentTransactionObjectForProgram(program: Program | string): Promise<Transaction>; /** * Returns the contents of the latest block as JSON. * * @returns {Promise<BlockJSON>} A javascript object containing the latest block * * @example * import { AleoNetworkClient } from "@provablehq/sdk/testnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * const latestHeight = networkClient.getLatestBlock(); */ getLatestBlock(): Promise<BlockJSON>; /** * Returns the latest committee. * * @returns {Promise<object>} A javascript object containing the latest committee * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * // Create a network client and get the latest committee. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * const latestCommittee = await networkClient.getLatestCommittee(); */ getLatestCommittee(): Promise<object>; /** * Returns the committee at the specified block height. * * @param {number} blockHeight - The height of the block to fetch the committee for * @returns {Promise<object>} A javascript object containing the committee * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * // Create a network client and get the committee for a specific block. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * const committee = await networkClient.getCommitteeByBlockHeight(1234); */ getCommitteeByBlockHeight(blockHeight: number): Promise<object>; /** * Returns the latest block height. * * @returns {Promise<number>} The latest block height. * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * const latestHeight = networkClient.getLatestHeight(); */ getLatestHeight(): Promise<number>; /** * Returns the latest block hash. * * @returns {Promise<string>} The latest block hash. * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * // Get the latest block hash. * const latestHash = networkClient.getLatestBlockHash(); */ getLatestBlockHash(): Promise<string>; /** * Returns the source code of a program given a program ID. * * @param {string} programId The program ID of a program deployed to the Aleo Network. * @param {number | undefined} edition The edition of the program to fetch. When this is undefined it will fetch the latest version. * @returns {Promise<string>} The source code of the program. * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * // Get the source code of a program.) * @returns {Promise<string>} Source code of the program * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * const program = networkClient.getProgram("hello_hello.aleo"); * const expectedSource = "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" * assert.equal(program, expectedSource); */ getProgram(programId: string, edition?: number): Promise<string>; /** * Returns the current program edition deployed on the Aleo network. * * @param {string} programId The program ID of a program deployed to the Aleo Network. * @returns {Promise<number>} The edition of the program. * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * const programVersion = networkClient.getLatestProgramEdition("hello_hello.aleo"); * assert.equal(programVersion, 1); */ getLatestProgramEdition(programId: string): Promise<number>; /** * Returns a program object from a program ID or program source code. * * @param {string} inputProgram The program ID or program source code of a program deployed to the Aleo Network. * @param {number | undefined} edition The edition of the program to fetch. When this is undefined it will fetch the latest version. * @returns {Promise<Program>} Source code of the program. * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * const programID = "hello_hello.aleo"; * 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;\n" * * // Get program object from program ID or program source code * const programObjectFromID = await networkClient.getProgramObject(programID); * const programObjectFromSource = await networkClient.getProgramObject(programSource); * * // Both program objects should be equal * assert(programObjectFromID.to_string() === programObjectFromSource.to_string()); */ getProgramObject(inputProgram: string, edition?: number): Promise<Program>; /** * Returns an object containing the source code of a program and the source code of all programs it imports * * @param {Program | string} inputProgram The program ID or program source code of a program deployed to the Aleo Network * @returns {Promise<ProgramImports>} Object of the form { "program_id": "program_source", .. } containing program id & source code for all program imports * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * const double_test_source = "import multiply_test.aleo;\n\nprogram double_test.aleo;\n\nfunction double_it:\n input r0 as u32.private;\n call multiply_test.aleo/multiply 2u32 r0 into r1;\n output r1 as u32.private;\n" * const double_test = Program.fromString(double_test_source); * const expectedImports = { * "multiply_test.aleo": "program multiply_test.aleo;\n\nfunction multiply:\n input r0 as u32.public;\n input r1 as u32.private;\n mul r0 r1 into r2;\n output r2 as u32.private;\n" * } * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * // Imports can be fetched using the program ID, source code, or program object * let programImports = await networkClient.getProgramImports("double_test.aleo"); * assert.deepStrictEqual(programImports, expectedImports); * * // Using the program source code * programImports = await networkClient.getProgramImports(double_test_source); * assert.deepStrictEqual(programImports, expectedImports); * * // Using the program object * programImports = await networkClient.getProgramImports(double_test); * assert.deepStrictEqual(programImports, expectedImports); */ getProgramImports(inputProgram: Program | string): Promise<ProgramImports>; /** * Get a list of the program names that a program imports. * * @param {Program | string} inputProgram - The program id or program source code to get the imports of * @returns {string[]} - The list of program names that the program imports * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * const programImportsNames = networkClient.getProgramImports("wrapped_credits.aleo"); * const expectedImportsNames = ["credits.aleo"]; * assert.deepStrictEqual(programImportsNames, expectedImportsNames); */ getProgramImportNames(inputProgram: Program | string): Promise<string[]>; /** * Returns the names of the mappings of a program. * * @param {string} programId - The program ID to get the mappings of (e.g. "credits.aleo") * @returns {Promise<Array<string>>} - The names of the mappings of the program. * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * const mappings = networkClient.getProgramMappingNames("credits.aleo"); * const expectedMappings = [ * "committee", * "delegated", * "metadata", * "bonded", * "unbonding", * "account", * "withdraw" * ]; * assert.deepStrictEqual(mappings, expectedMappings); */ getProgramMappingNames(programId: string): Promise<Array<string>>; /** * Returns the value of a program's mapping for a specific key. * * @param {string} programId - The program ID to get the mapping value of (e.g. "credits.aleo") * @param {string} mappingName - The name of the mapping to get the value of (e.g. "account") * @param {string | Plaintext} key - The key to look up in the mapping (e.g. an address for the "account" mapping) * @returns {Promise<string>} String representation of the value of the mapping * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * // Get public balance of an account * const mappingValue = networkClient.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px"); * const expectedValue = "0u64"; * assert(mappingValue === expectedValue); */ getProgramMappingValue(programId: string, mappingName: string, key: string | Plaintext): Promise<string>; /** * Returns the value of a mapping as a wasm Plaintext object. Returning an object in this format allows it to be converted to a Js type and for its internal members to be inspected if it's a struct or array. * * @param {string} programId - The program ID to get the mapping value of (e.g. "credits.aleo") * @param {string} mappingName - The name of the mapping to get the value of (e.g. "bonded") * @param {string | Plaintext} key - The key to look up in the mapping (e.g. an address for the "bonded" mapping) * @returns {Promise<Plaintext>} String representation of the value of the mapping * * @example * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * // Get the bond state as an account. * const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px"); * * // Get the two members of the object individually. * const validator = unbondedState.getMember("validator"); * const microcredits = unbondedState.getMember("microcredits"); * * // Ensure the expected values are correct. * assert.equal(validator, "aleo1u6940v5m0fzud859xx2c9tj2gjg6m5qrd28n636e6fdd2akvfcgqs34mfd"); * assert.equal(microcredits, BigInt("9007199254740991")); * * // Get a JS object representation of the unbonded state. * const unbondedStateObject = unbondedState.toObject(); * * const expectedState = { * validator: "aleo1u6940v5m0fzud859xx2c9tj2gjg6m5qrd28n636e6fdd2akvfcgqs34mfd", * microcredits: BigInt(9007199254740991) * }; * assert.equal(unbondedState, expectedState); */ getProgramMappingPlaintext(programId: string, mappingName: string, key: string | Plaintext): Promise<Plaintext>; /** * Returns the public balance of an address from the account mapping in credits.aleo * * @param {Address | string} address A string or wasm object representing an address. * @returns {Promise<number>} The public balance of the address in microcredits. * * @example * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", 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); */ getPublicBalance(address: Address | string): Promise<number>; /** * Returns the latest state/merkle root of the Aleo blockchain. * * @returns {Promise<string>} A string representing the latest state root of the Aleo blockchain. * * @example * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * // Get the latest state root. * const stateRoot = networkClient.getStateRoot(); */ getStateRoot(): Promise<string>; /** * Returns a transaction by its unique identifier. * * @param {string} transactionId The transaction ID to fetch. * @returns {Promise<TransactionJSON>} A json representation of the transaction. * * @example * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * const transaction = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj"); */ getTransaction(transactionId: string): Promise<TransactionJSON>; /** * Returns a confirmed transaction by its unique identifier. * * @param {string} transactionId The transaction ID to fetch. * @returns {Promise<ConfirmedTransactionJSON>} A json object containing the confirmed transaction. * * @example * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * const transaction = networkClient.getConfirmedTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj"); * assert.equal(transaction.status, "confirmed"); */ getConfirmedTransaction(transactionId: string): Promise<ConfirmedTransactionJSON>; /** * Returns a transaction as a wasm object. Getting a transaction of this type will allow the ability for the inputs, * outputs, and records to be searched for and displayed. * * @param {string} transactionId - The unique identifier of the transaction to fetch * @returns {Promise<Transaction>} A wasm object representation of the transaction. * * @example * const transactionObject = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj"); * // Get the transaction inputs as a JS array. * const transactionInputs = transactionObject.inputs(true); * * // Get the transaction outputs as a JS object. * const transactionOutputs = transactionObject.outputs(true); * * // Get any records generated in transitions in the transaction as a JS object. * const records = transactionObject.records(); * * // Get the transaction type. * const transactionType = transactionObject.transactionType(); * assert.equal(transactionType, "Execute"); * * // Get a JS representation of all inputs, outputs, and transaction metadata. * const transactionSummary = transactionObject.summary(); */ getTransactionObject(transactionId: string): Promise<Transaction>; /** * Returns the transactions present at the specified block height. * * @param {number} blockHeight The block height to fetch the confirmed transactions at. * @returns {Promise<Array<ConfirmedTransactionJSON>>} An array of confirmed transactions (in JSON format) for the block height. * * @example * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * const transactions = networkClient.getTransactions(654); */ getTransactions(blockHeight: number): Promise<Array<ConfirmedTransactionJSON>>; /** * Returns the confirmed transactions present in the block with the specified block hash. * * @param {string} blockHash The block hash to fetch the confirmed transactions at. * @returns {Promise<Array<ConfirmedTransactionJSON>>} An array of confirmed transactions (in JSON format) for the block hash. * * @example * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * const transactions = networkClient.getTransactionsByBlockHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9"); */ getTransactionsByBlockHash(blockHash: string): Promise<Array<ConfirmedTransactionJSON>>; /** * Returns the transactions in the memory pool. This method requires access to a validator's REST API. * * @returns {Promise<Array<TransactionJSON>>} An array of transactions (in JSON format) currently in the mempool. * * @example * import { AleoNetworkClient, Account } from "@provablehq/sdk/mainnet.js"; * * // Create a network client. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * * // Get the current transactions in the mempool. * const transactions = networkClient.getTransactionsInMempool(); */ getTransactionsInMempool(): Promise<Array<TransactionJSON>>; /** * Returns the transition ID of the transition corresponding to the ID of the input or output. * @param {string} inputOrOutputID - The unique identifier of the input or output to find the transition ID for * @returns {Promise<string>} - The transition ID of the input or output ID. * * @example * const transitionId = networkClient.getTransitionId("2429232855236830926144356377868449890830704336664550203176918782554219952323field"); */ getTransitionId(inputOrOutputID: string): Promise<string>; /** * Submit an execute or deployment transaction to the Aleo network. * * @param {Transaction | string} transaction - The transaction to submit, either as a Transaction object or string representation * @returns {Promise<string>} - The transaction id of the submitted transaction or the resulting error */ submitTransaction(transaction: Transaction | string): Promise<string>; /** * Submit a solution to the Aleo network. * * @param {string} solution - The string representation of the solution to submit * @returns {Promise<string>} The solution id of the submitted solution or the resulting error. */ submitSolution(solution: string): Promise<string>; /** * Submit a `ProvingRequest` to a remote proving service for delegated proving. If the broadcast flag of the `ProvingRequest` is set to `true` the remote service will attempt to broadcast the result `Transaction` on behalf of the requestor. * * @param {DelegatedProvingParams} options - The optional parameters required to submit a proving request. * @returns {Promise<ProvingResponse>} The ProvingResponse containing the transaction result and the result of the broadcast if the `broadcast` flag was set to `true`. */ submitProvingRequest(options: DelegatedProvingParams): Promise<ProvingResponse>; /** * Await a submitted transaction to be confirmed or rejected on the Aleo network. * * @param {string} transactionId - The transaction ID to wait for confirmation * @param {number} checkInterval - The interval in milliseconds to check for confirmation (default: 2000) * @param {number} timeout - The maximum time in milliseconds to wait for confirmation (default: 45000) * @returns {Promise<Transaction>} The confirmed transaction object that returns if the transaction is confirmed. * * @example * import { AleoNetworkClient, Account, ProgramManager } from "@provablehq/sdk/mainnet.js"; * * // Create a network client and program manager. * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined); * const programManager = new ProgramManager(networkClient); * * // Set the account for the program manager. * programManager.setAccount(Account.fromCiphertext(process.env.ciphertext, process.env.password)); * * // Build a transfer transaction. * const tx = await programManager.buildTransferPublicTransaction(100, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", 0); * * // Submit the transaction to the network. * const transactionId = await networkClient.submitTransaction(tx); * * // Wait for the transaction to be confirmed. * const transaction = await networkClient.waitForTransactionConfirmation(transactionId); */ waitForTransactionConfirmation(transactionId: string, checkInterval?: number, timeout?: number): Promise<ConfirmedTransactionJSON>; } export { AleoNetworkClient, AleoNetworkClientOptions, ProgramImports };