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

Create a new NetworkRecordProvider instance to find records for program execution and deployment.

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

Example

import { AleoNetworkClient, Account, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";

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

RecordProvider Interface

The RecordProvider interface defines the contract for finding records for use in deployment and execution transactions on the Aleo Network. A default implementation is provided by the NetworkRecordProvider class. However, a custom implementation can be provided (say if records are synced locally to a database from the network) by implementing this interface.

encryptedRecords

Find encrypted records from the chosen provider.

encryptedRecords(recordsFilter, responseFilter)Promise.<EncryptedRecord[]>
ParametersTypeDescription
recordsFilterRecordSearchParamsThe filter used to find the records
responseFilterRecordsResponseFilterOptional filter used to filter the response
returnPromise.<EncryptedRecord[]>The encrypted records

checkSerialNumbers

Check if a list of serial numbers exist in the chosen provider.

checkSerialNumbers(serialNumbers)Promise.<Record<string, boolean>>
ParametersTypeDescription
serialNumbersstring[]The serial numbers to check
returnPromise.<Record<string, boolean>>Map of Aleo Record serial numbers and whether they appeared in any inputs on chain. If boolean corresponding to the Serial Number has a true value, that Record is considered spent by the Aleo Network.

checkTags

Check if a list of tags exist in the chosen provider.

checkTags(tags)Promise.<Record<string, boolean>>
ParametersTypeDescription
tagsstring[]The tags to check
returnPromise.<Record<string, boolean>>Map of Aleo Record tags and whether they appeared in any inputs on chain. If boolean corresponding to the tag has a true value, that Record is considered spent by the Aleo Network.

NetworkRecordProvider 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 via the official Aleo API

findCreditsRecords(microcredits, searchParameters)Promise.<OwnedRecord[]>
ParametersTypeDescription
microcreditsnumber[]The number of microcredits to search for
searchParametersRecordSearchParamsAdditional parameters to search for (includes unspent and nonces)
returnPromise.<OwnedRecord[]>The records 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, { unspent: true, nonces: [] });

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

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

findCreditsRecord

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

findCreditsRecord(microcredits, searchParameters)Promise.<OwnedRecord>
ParametersTypeDescription
microcreditsnumberThe number of microcredits to search for
searchParametersRecordSearchParamsAdditional parameters to search for (includes unspent and nonces)
returnPromise.<OwnedRecord>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, { unspent: true, nonces: [] });

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

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

findRecord

Find an arbitrary record.

findRecord(searchParameters)Promise.<OwnedRecord>
ParametersTypeDescription
searchParametersRecordSearchParamsParameters to search for
returnPromise.<OwnedRecord>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
const record = await recordProvider.findRecord({ unspent: true, nonces: [] });

findRecords

Find multiple records from a specified program.

findRecords(searchParameters)Promise.<OwnedRecord[]>
ParametersTypeDescription
searchParametersRecordSearchParamsParameters to search for
returnPromise.<OwnedRecord[]>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({ unspent: true, nonces: [] });

Class BlockHeightSearch

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

Constructor

Create a new BlockHeightSearch instance to search for records within a specific block height range.

new BlockHeightSearch(startHeight, endHeight, unspent)
ParamTypeDescription
startHeightnumberThe starting block height
endHeightnumberThe ending block height
unspentbooleanOptional. Whether to search for unspent records only

Examples

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

// 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, { unspent: true, nonces: [], ...params });