Skip to main content

Record Provider

Overview

A record provider implementation that uses the official Aleo API to find records for usage in program execution and deployment, wallet functionality, and other use cases.

Kind: global class

Constructor

NetworkRecordProvider

new NetworkRecordProvider(account, networkClient)
ParamTypeDescription
accountAccountThe account to use for searching for records
networkClientAleoNetworkClientThe network client to use for API calls

Example

// Create a new NetworkRecordProvider
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const account = new Account();
const recordProvider = new NetworkRecordProvider(account, networkClient);

Methods

setAccount

Set the account used to search for records

setAccount(account)
ParametersTypeDescription
accountAccountThe account to use for searching for records

Example

// Set a new account for the record provider
const newAccount = new Account();
recordProvider.setAccount(newAccount);

findCreditsRecords

Find a list of credit records with a given number of microcredits by via the official Aleo API

findCreditsRecords(microcredits, unspent, nonces, searchParameters)
ParametersTypeDescription
microcreditsArray.<number>The number of microcredits to search for
unspentbooleanWhether or not the record is unspent
noncesArray.<string>Nonces of records already found so that they are not found again
searchParametersRecordSearchParamsAdditional parameters to search for
returnPromise.<RecordPlaintext>The record if found, otherwise an error

Example

// Create a new NetworkRecordProvider
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const keyProvider = new AleoKeyProvider();
const recordProvider = new NetworkRecordProvider(account, networkClient);

// The record provider can be used to find records with a given number of microcredits
const record = await recordProvider.findCreditsRecord(5000, true, []);

// When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
// found again if a subsequent search is performed
const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);

// When the program manager is initialized with the record provider it will be used to find automatically find
// fee records and amount records for value transfers so that they do not need to be specified manually
const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);

findCreditsRecord

Find a credit record with a given number of microcredits by via the official Aleo API

findCreditsRecord(microcredits, unspent, nonces, searchParameters)
ParametersTypeDescription
microcreditsnumberThe number of microcredits to search for
unspentbooleanWhether or not the record is unspent
noncesArray.<string>Nonces of records already found so that they are not found again
searchParametersRecordSearchParamsAdditional parameters to search for
returnPromise.<RecordPlaintext>The record if found, otherwise an error

Example

// Create a new NetworkRecordProvider
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const keyProvider = new AleoKeyProvider();
const recordProvider = new NetworkRecordProvider(account, networkClient);

// The record provider can be used to find records with a given number of microcredits
const record = await recordProvider.findCreditsRecord(5000, true, []);

// When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
// found again if a subsequent search is performed
const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);

// When the program manager is initialized with the record provider it will be used to find automatically find
// fee records and amount records for value transfers so that they do not need to be specified manually
const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);

findRecord

Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.

findRecord(unspent, nonces, searchParameters)
ParametersTypeDescription
unspentbooleanWhether or not the record is unspent
noncesArray.<string>Nonces of records already found so that they are not found again
searchParametersRecordSearchParamsAdditional parameters to search for
returnPromise.<RecordPlaintext>The record if found, otherwise an error

Example

// Create a new NetworkRecordProvider
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const recordProvider = new NetworkRecordProvider(account, networkClient);

// Find an arbitrary record (not yet implemented)
try {
const record = await recordProvider.findRecord(true, [], null);
} catch (error) {
console.log("findRecord is not yet implemented");
}

findRecords

Find multiple records from a specified program.

findRecords(unspent, nonces, searchParameters)
ParametersTypeDescription
unspentbooleanWhether or not the records are unspent
noncesArray.<string>Nonces of records already found so that they are not found again
searchParametersRecordSearchParamsAdditional parameters to search for
returnPromise.<Array.<RecordPlaintext>>Array of records if found, otherwise an error

Example

// Create a new NetworkRecordProvider
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const recordProvider = new NetworkRecordProvider(account, networkClient);

// Find multiple records from a specified program
const records = await recordProvider.findRecords(true, [], null);

Class BlockHeightSearch

BlockHeightSearch is a RecordSearchParams implementation that allows for searching for records within a given block height range.

Examples

// Create a new BlockHeightSearch
const params = new BlockHeightSearch(89995, 99995);

// Create a new NetworkRecordProvider
const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
const keyProvider = new AleoKeyProvider();
const recordProvider = new NetworkRecordProvider(account, networkClient);

// The record provider can be used to find records with a given number of microcredits and the block height search
// can be used to find records within a given block height range
const record = await recordProvider.findCreditsRecord(5000, true, [], params);