Aleo Network Client
Overview
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.
Kind: global class
- AleoNetworkClient
- constructor
- instance
- .setHost(host)
- .setAccount(account)
- .getAccount() ⇒
Account|undefined - .setVerboseErrors(verboseErrors)
- .setHeader(headerName, value)
- .removeHeader(headerName)
- .fetchData(url) ⇒
Promise.<T> - .fetchRaw(url) ⇒
Promise.<string> - .findRecords(startHeight, endHeight, unspent, programs, amounts, maxMicrocredits, nonces, privateKey) ⇒
Promise.<Array.<RecordPlaintext>> - .findUnspentRecords(startHeight, endHeight, programs, amounts, maxMicrocredits, nonces, privateKey) ⇒
Promise.<Array.<RecordPlaintext>> - .getBlock(height) ⇒
Promise.<BlockJSON> - .getBlockByHash(blockHash) ⇒
Promise.<BlockJSON> - .getBlockRange(start, end) ⇒
Promise.<Array.<BlockJSON>> - .getProgram(programId, edition) ⇒
Promise.<string> - .getLatestProgramEdition(programId) ⇒
Promise.<number> - .getProgramObject(inputProgram, edition) ⇒
Promise.<Program> - .getProgramImports(inputProgram) ⇒
Promise.<ProgramImports> - .getProgramImportNames(inputProgram) ⇒
Array.<string> - .getDeploymentTransactionIDForProgram(program) ⇒
Promise.<string> - .getDeploymentTransactionForProgram(program) ⇒
Promise.<TransactionJSON> - .getDeploymentTransactionObjectForProgram(program) ⇒
Promise.<Transaction> - .getProgramMappingNames(programId) ⇒
Promise.<Array.<string>> - .getProgramMappingValue(programId, mappingName, key) ⇒
Promise.<string> - .getProgramMappingPlaintext(programId, mappingName, key) ⇒
Promise.<Plaintext> - .getPublicBalance(address) ⇒
Promise.<number> - .getLatestBlock() ⇒
Promise.<BlockJSON> - .getLatestHeight() ⇒
Promise.<number> - .getLatestBlockHash() ⇒
Promise.<string> - .getLatestCommittee() ⇒
Promise.<object> - .getCommitteeByBlockHeight(blockHeight) ⇒
Promise.<object> - .getStateRoot() ⇒
Promise.<string> - .getTransaction(id) ⇒
Promise.<TransactionJSON> - .getConfirmedTransaction(transactionId) ⇒
Promise.<ConfirmedTransactionJSON> - .getTransactionObject(transactionId) ⇒
Promise.<Transaction> - .getTransactions(height) ⇒
Promise.<Array.<ConfirmedTransactionJSON>> - .getTransactionsByBlockHash(blockHash) ⇒
Promise.<Array.<ConfirmedTransactionJSON>> - .getTransactionsInMempool() ⇒
Promise.<Array.<TransactionJSON>> - .getTransitionId(inputOrOutputID) ⇒
Promise.<string> - .submitTransaction(transaction) ⇒
Promise.<string> - .submitSolution(solution) ⇒
Promise.<string> - .submitProvingRequest(options) ⇒
Promise.<ProvingResponse> - .waitForTransactionConfirmation(transactionId, checkInterval, timeout) ⇒
Promise.<ConfirmedTransactionJSON>
Constructor
AleoNetworkClient
Create a new AleoNetworkClient instance to interact with the Aleo network.
new AleoNetworkClient(host, options)
| Param | Type | Description |
|---|---|---|
| host | string | The URL of the Aleo node to connect to |
| options | AleoNetworkClientOptions | Optional configuration options |
Interface
interface AleoNetworkClientOptions {
headers?: Record<string, string>;
}
| Property | Type | Description |
|---|---|---|
| headers | Record<string, string> | Optional headers to include in all requests |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
// Connection to a local node
const localConnection = new AleoNetworkClient("http://localhost:3030");
// Connection to a public beacon node
const publicConnection = new AleoNetworkClient("https://api.explorer.provable.com/v1");
// Connection with custom headers
const customConnection = new AleoNetworkClient("https://api.explorer.provable.com/v1", {
headers: { "Authorization": "Bearer token" }
});
Methods
setHost
Set a new host for the networkClient
networkClient.setHost(host)
| Param | Type | Description |
|---|---|---|
| host | string | The URL of the Aleo node to connect to |
Example
// New connection to a public beacon node
let public_connection = AleoNetworkClient.setHost("https://api.explorer.provable.com/v1");
setAccount
Set an account to use in networkClient calls
networkClient.setAccount(account)
| Param | Type | Description |
|---|---|---|
| account | Account | The account to use for networkClient calls |
Example
let account = new Account();
networkClient.setAccount(account);
getAccount
Return the Aleo account used in the networkClient
networkClient.getAccount() ⇒ Account | undefined
| Param | Type | Description |
|---|---|---|
| return | Account | undefined | The account if set, otherwise undefined |
Example
let account = networkClient.getAccount();
setVerboseErrors
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.
networkClient.setVerboseErrors(verboseErrors)
| Param | Type | Description |
|---|---|---|
| verboseErrors | boolean | Set verbose error mode to true or false |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
// Create a networkClient
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
// Set verbose mode to true
networkClient.setVerboseErrors(true);
setHeader
Set a header in the AleoNetworkClient's header map
networkClient.setHeader(headerName, value)
| Param | Type | Description |
|---|---|---|
| headerName | string | The name of the header to set |
| value | string | The header value |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
// Create a networkClient
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
// Set the value of the `Accept-Language` header to `en-US`
networkClient.setHeader('Accept-Language', 'en-US');
removeHeader
Remove a header from the AleoNetworkClient's header map
networkClient.removeHeader(headerName)
| Param | Type | Description |
|---|---|---|
| headerName | string | The name of the header to remove |
fetchData
Fetches data from the Aleo network and returns it as a JSON object.
networkClient.fetchData(url) ⇒ Promise.<Type>
| Param | Type | Description |
|---|---|---|
| url | string | The URL to fetch data from |
| return | Promise.<Type> | A JSON object parsed from the response |
fetchRaw
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.
networkClient.fetchRaw(url) ⇒ Promise.<string>
| Param | Type | Description |
|---|---|---|
| url | string | The URL to fetch data from |
| return | Promise.<string> | The raw response as an unparsed string |
findRecords
Attempt to find records in the Aleo blockchain.
networkClient.findRecords(startHeight, endHeight, unspent, programs, amounts, maxMicrocredits, nonces, privateKey) ⇒ Promise.<Array.<RecordPlaintext>>
| Param | Type | Description |
|---|---|---|
| startHeight | number | The height at which to start searching for unspent records |
| endHeight | number | The height at which to stop searching for unspent records |
| unspent | boolean | Whether to search for unspent records only |
| programs | Array.<string> | The program(s) to search for unspent records in |
| amounts | Array.<number> | The amounts (in microcredits) to search for (eg. [100, 200, 3000]) |
| maxMicrocredits | number | The maximum number of microcredits to search for |
| nonces | Array.<string> | The nonces of already found records to exclude from the search |
| privateKey | string | An optional private key to use to find unspent records. |
| return | Promise.<Array.<RecordPlaintext>> | Array of decrypted record plaintexts |
Example
// Find specific amounts
const startHeight = 500000;
const amounts = [600000, 1000000];
const records = await networkClient.findRecords(startHeight, undefined, true, ["credits.aleo"], amounts);
// Find specific amounts with a maximum number of cumulative microcredits
const maxMicrocredits = 100000;
const records = await networkClient.findRecords(startHeight, undefined, true, ["credits.aleo"], undefined, maxMicrocredits);
findUnspentRecords
Attempts to find unspent records in the Aleo blockchain.
networkClient.findUnspentRecords(startHeight, endHeight, programs, amounts, maxMicrocredits, nonces, privateKey) ⇒ Promise.<Array.<RecordPlaintext>>
| Param | Type | Description |
|---|---|---|
| startHeight | number | The height at which to start searching for unspent records |
| endHeight | number | The height at which to stop searching for unspent records |
| programs | Array.<string> | The program(s) to search for unspent records in |
| amounts | Array.<number> | The amounts (in microcredits) to search for (eg. [100, 200, 3000]) |
| maxMicrocredits | number | The maximum number of microcredits to search for |
| nonces | Array.<string> | The nonces of already found records to exclude from the search |
| privateKey | string | An optional private key to use to find unspent records. |
| return | Promise.<Array.<RecordPlaintext>> | Array of decrypted unspent record plaintexts |
Example
// Find specific amounts
const startHeight = 500000;
const endHeight = 550000;
const amounts = [600000, 1000000];
const records = await networkClient.findUnspentRecords(startHeight, endHeight, ["credits.aleo"], amounts);
// Find specific amounts with a maximum number of cumulative microcredits
const maxMicrocredits = 100000;
const records = await networkClient.findUnspentRecords(startHeight, undefined, ["credits.aleo"], undefined, maxMicrocredits);
getBlock
Returns the contents of the block at the specified block height.
networkClient.getBlock(height) ⇒ Promise.<BlockJSON>
| Param | Type | Description |
|---|---|---|
| height | number | The block height to fetch |
| return | Promise.<BlockJSON> | A JSON representation of the block |
Example
let block = await networkClient.getBlock(1234);
getBlockByHash
Returns the contents of the block with the specified hash.
networkClient.getBlockByHash(blockHash) ⇒ Promise.<BlockJSON>
| Param | Type | Description |
|---|---|---|
| blockHash | string | The hash of the block to fetch |
| return | Promise.<BlockJSON> | A javascript object representation of the block matching the hash |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const block = await networkClient.getBlockByHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
getBlockRange
Returns a range of blocks between the specified block heights. A maximum of 50 blocks can be fetched at a time.
networkClient.getBlockRange(start, end) ⇒ Promise.<Array.<BlockJSON>>
| Param | Type | Description |
|---|---|---|
| start | number | The starting block height |
| end | number | The ending block height |
| return | Promise.<Array.<BlockJSON>> | Array of blocks in the specified range |
Example
let blockRange = await networkClient.getBlockRange(2050, 2100);
getProgram
Returns the source code of a program given a program ID.
networkClient.getProgram(programId, edition) ⇒ Promise.<string>
| Param | Type | Description |
|---|---|---|
| programId | string | The program ID of a program deployed to the Aleo Network |
| edition | number | undefined | Optional edition of the program to fetch. When undefined, fetches the latest version. |
| return | Promise.<string> | Source code of the program |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const program = await 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);
getLatestProgramEdition
Returns the current program edition deployed on the Aleo network.
networkClient.getLatestProgramEdition(programId) ⇒ Promise.<number>
| Param | Type | Description |
|---|---|---|
| programId | string | The program ID of a program deployed to the Aleo Network |
| return | Promise.<number> | The edition of the program |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const programEdition = await networkClient.getLatestProgramEdition("hello_hello.aleo");
assert.equal(programEdition, 1);
getProgramObject
Returns a program object from a program ID or program source code.
networkClient.getProgramObject(inputProgram, edition) ⇒ Promise.<Program>
| Param | Type | Description |
|---|---|---|
| inputProgram | string | The program ID or program source code of a program deployed to the Aleo Network |
| edition | number | undefined | Optional edition of the program to fetch. When undefined, fetches the latest version. |
| return | Promise.<Program> | Source code of the program |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
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());
getProgramImports
Returns an object containing the source code of a program and the source code of all programs it imports
networkClient.getProgramImports(inputProgram) ⇒ Promise.<ProgramImports>
| Param | Type | Description |
|---|---|---|
| inputProgram | Program | The program ID or program source code of a program deployed to the Aleo Network |
| return | Promise.<ProgramImports> |
Example
let program = await networkClient.getProgramImports("double_test.aleo");
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"
}
// 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);
getProgramImportNames
Get a list of the program names that a program imports.
networkClient.getProgramImportNames(inputProgram) ⇒ Array.<string>
| Param | Type | Description |
|---|---|---|
| inputProgram | Program | The program id or program source code to get the imports of |
| return | Array.<string> | Array of program names that the input program imports |
Example
let mappings = networkClient.getProgramImportNames("double_test.aleo");
const expectedImportsNames = ["multiply_test.aleo"];
assert.deepStrictEqual(programImportsNames, expectedImportsNames);
getDeploymentTransactionIDForProgram
Returns the deployment transaction id associated with the specified program.
networkClient.getDeploymentTransactionIDForProgram(program) ⇒ TransactionJSON
| Param | Type | Description |
|---|---|---|
| program | Program | The program ID to look up |
| return | Promise.<string> | The transaction ID of the deployment |
Example
let program = networkClient.getDeploymentTransactionIDForProgram("foo.aleo");
getDeploymentTransactionForProgram
Returns the deployment transaction associated with a specified program.
networkClient.getDeploymentTransactionForProgram(program) ⇒ TransactionJSON
| Param | Type | Description |
|---|---|---|
| program | Program | The program ID to look up |
| return | Promise.<TransactionJSON> | The deployment transaction JSON |
Example
let program = networkClient.getDeploymentTransactionForProgram("foo.aleo");
getDeploymentTransactionObjectForProgram
Returns the deployment transaction associated with a specified program as a wasm object.
networkClient.getDeploymentTransactionObjectForProgram(program) ⇒ TransactionJSON
| Param | Type | Description |
|---|---|---|
| program | Program | The program ID to look up |
| return | Promise.<Transaction> | The deployment transaction as a WASM object |
getProgramMappingNames
Returns the names of the mappings of a program.
networkClient.getProgramMappingNames(programId) ⇒ Promise.<Array.<string>>
| Param | Type | Description |
|---|---|---|
| programId | string | The program ID to get the mappings of (e.g. "credits.aleo") |
| return | Promise.<Array.<string>> | Array of mapping names in the program |
Example
let mappings = await networkClient.getProgramMappingNames("credits.aleo");
const expectedMappings = [
"committee",
"delegated",
"metadata",
"bonded",
"unbonding",
"account",
"withdraw"
];
assert.deepStrictEqual(mappings, expectedMappings);
getProgramMappingValue
Returns the value of a program's mapping for a specific key.
networkClient.getProgramMappingValue(programId, mappingName, key) ⇒ Promise.<string>
| Param | Type | Description |
|---|---|---|
| programId | string | The program ID to get the mapping value of (e.g. "credits.aleo") |
| mappingName | string | The name of the mapping to get the value of (e.g. "account") |
| key | string | The key of the mapping to get the value of (e.g. "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px") |
| return | Promise.<string> | The value at the specified key as a string |
Example
// Get public balance of an account
let mappingValue = await networkClient.getProgramMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
const expectedValue = "0u64";
assert.equal(mappingValue, expectedValue);
getProgramMappingPlaintext
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.
networkClient.getProgramMappingPlaintext(programId, mappingName, key) ⇒ Promise.<string>
| Param | Type | Description |
|---|---|---|
| programId | string | The program ID to get the mapping value of (e.g. "credits.aleo") |
| mappingName | string | The name of the mapping to get the value of (e.g. "account") |
| key | string | The key of the mapping to get the value of (e.g. "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px") |
| return | Promise.<Plaintext> | The value as a Plaintext WASM object |
Example
// Get the bond state as an account.
const unbondedState = await networkClient.getProgramMappingPlaintext("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.deepEqual(unbondedStateObject, expectedState);
getPublicBalance
Returns the public balance of an address from the account mapping in credits.aleo
networkClient.getPublicBalance(address) ⇒ Promise.<number>
| Param | Type | Description |
|---|---|---|
| address | Address | string | A string or wasm object representing an address |
| return | 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("https://api.explorer.provable.com/v1");
// 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);
getLatestBlock
Returns the contents of the latest block.
networkClient.getLatestBlock() ⇒ Promise.<BlockJSON>
| Param | Type | Description |
|---|---|---|
| return | Promise.<BlockJSON> | The latest block as JSON |
Example
let latestHeight = await networkClient.getLatestBlock();
getLatestHeight
Returns the latest block height.
networkClient.getLatestHeight() ⇒ Promise.<number>
| Param | Type | Description |
|---|---|---|
| return | Promise.<number> | The latest block height |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const latestHeight = await networkClient.getLatestHeight();
getLatestBlockHash
Returns the latest block hash.
networkClient.getLatestBlockHash() ⇒ Promise.<string>
| Param | Type | Description |
|---|---|---|
| return | Promise.<string> | The latest block hash |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const latestHash = await networkClient.getLatestBlockHash();
getLatestCommittee
Returns the latest committee.
networkClient.getLatestCommittee() ⇒ Promise.<object>
| Param | Type | Description |
|---|---|---|
| return | Promise.<object> | The current validator committee |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const latestCommittee = await networkClient.getLatestCommittee();
getCommitteeByBlockHeight
Returns the committee at the specified block height.
networkClient.getCommitteeByBlockHeight(blockHeight) ⇒ Promise.<object>
| Param | Type | Description |
|---|---|---|
| blockHeight | number | The height of the block to fetch the committee for |
| return | Promise.<object> | A javascript object containing the committee |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const committee = await networkClient.getCommitteeByBlockHeight(1234);
getStateRoot
Returns the latest state/merkle root of the Aleo blockchain.
networkClient.getStateRoot() ⇒ Promise.<string>
| Param | Type | Description |
|---|---|---|
| return | Promise.<string> | The current state/merkle root |
Example
let stateRoot = await networkClient.getStateRoot();
getTransaction
Returns a transaction by its unique identifier.
networkClient.getTransaction(id) ⇒ Promise.<TransactionJSON>
| Param | Type | Description |
|---|---|---|
| id | string | The transaction ID to look up |
| return | Promise.<TransactionJSON> | The transaction as JSON |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const transaction = await networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
getConfirmedTransaction
Returns a confirmed transaction by its unique identifier.
networkClient.getConfirmedTransaction(transactionId) ⇒ Promise.<ConfirmedTransactionJSON>
| Param | Type | Description |
|---|---|---|
| transactionId | string | The transaction ID to fetch |
| return | Promise.<ConfirmedTransactionJSON> | A json object containing the confirmed transaction |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const transaction = await networkClient.getConfirmedTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
assert.equal(transaction.status, "accepted");
getTransactionObject
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.
networkClient.getTransactionObject(transactionId) ⇒ Promise.<Transaction>
| Param | Type | Description |
|---|---|---|
| transactionId | string | The transaction ID to look up |
| return | Promise.<Transaction> | The transaction as a WASM object |
Example
const transactionObject = await networkClient.getTransactionObject("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
// Get the transaction inputs as a JS array.
const transactionOutputs = transactionObject.inputs(true);
// Get the transaction outputs as a JS object.
const transactionInputs = 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();
getTransactions
Returns the transactions present at the specified block height.
networkClient.getTransactions(height) ⇒ Promise.<Array.<ConfirmedTransactionJSON>>
| Param | Type | Description |
|---|---|---|
| height | number | The block height to fetch transactions for |
| return | Promise.<Array.<ConfirmedTransactionJSON>> | Array of confirmed transactions |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const transactions = await networkClient.getTransactions(654);
getTransactionsByBlockHash
Returns the confirmed transactions present in the block with the specified block hash.
networkClient.getTransactionsByBlockHash(blockHash) ⇒ Promise.<Array.<ConfirmedTransactionJSON>>
| Param | Type | Description |
|---|---|---|
| blockHash | string | The block hash to fetch the confirmed transactions at |
| return | Promise.<Array.<ConfirmedTransactionJSON>> | An array of confirmed transactions (in JSON format) for the block hash |
Example
import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const transactions = await networkClient.getTransactionsByBlockHash("ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9");
getTransactionsInMempool
Returns the transactions in the memory pool. This method requires access to a validator's REST API.
networkClient.getTransactionsInMempool() ⇒ Promise.<Array.<TransactionJSON>>
| Param | Type | Description |
|---|---|---|
| return | Promise.<Array.<TransactionJSON>> | Array of transactions currently in the mempool |
Example
let transactions = await networkClient.getTransactionsInMempool();
getTransitionId
Returns the transition ID of the transition corresponding to the ID of the input or output.
networkClient.getTransitionId(inputOrOutputID) ⇒ Promise.<string>
| Param | Type | Description |
|---|---|---|
| inputOrOutputID | string | ID of the input or output. |
| return | Promise.<string> | The transition ID containing the input or output |
Example
let transition = await networkClient.getTransitionId("2429232855236830926144356377868449890830704336664550203176918782554219952323field");
submitTransaction
Submit an execute or deployment transaction to the Aleo network.
networkClient.submitTransaction(transaction) ⇒ string
| Param | Type | Description |
|---|---|---|
| transaction | Transaction | The transaction to submit to the network |
| return | Promise.<string> | The transaction ID of the submitted transaction |
submitSolution
Submit a solution to the Aleo network.
networkClient.submitSolution(solution) ⇒ Promise.<string>
| Param | Type | Description |
|---|---|---|
| solution | string | The string representation of the solution desired to be submitted to the network. |
| return | Promise.<string> | The solution id of the submitted solution or the resulting error |
submitProvingRequest
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.
networkClient.submitProvingRequest(options) ⇒ Promise.<ProvingResponse>
| Param | Type | Description |
|---|---|---|
| options | DelegatedProvingParams | The optional parameters required to submit a proving request |
| return | Promise.<ProvingResponse> | The ProvingResponse containing the transaction result and the result of the broadcast if the broadcast flag was set to true |
DelegatedProvingParams Interface
| Property | Type | Description |
|---|---|---|
| provingRequest | ProvingRequest | string | The proving request being submitted to the network |
| url | string | Optional URL of the delegated proving service |
| apiKey | string | Optional API key used for generating a JWT |
| consumerId | string | Optional consumer ID associated with the API key |
| jwtData | JWTData | Optional JWT token used for authenticating with the proving service |
waitForTransactionConfirmation
Await a submitted transaction to be confirmed or rejected on the Aleo network.
networkClient.waitForTransactionConfirmation(transactionId, checkInterval, timeout) ⇒ Promise.<ConfirmedTransactionJSON>
| Param | Type | Description |
|---|---|---|
| transactionId | string | The transaction ID to wait for confirmation |
| checkInterval | number | The interval in milliseconds to check for confirmation (default: 2000) |
| timeout | number | The maximum time in milliseconds to wait for confirmation (default: 45000) |
| return | Promise.<ConfirmedTransactionJSON> | 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("https://api.explorer.provable.com/v1");
const programManager = new ProgramManager("https://api.explorer.provable.com/v1");
// 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);