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
-
RecordProvider (Interface)
- interface methods
- .encryptedRecords(recordsFilter, responseFilter) ⇒
Promise.<EncryptedRecord[]> - .checkSerialNumbers(serialNumbers) ⇒
Promise.<Record<string, boolean>> - .checkTags(tags) ⇒
Promise.<Record<string, boolean>> - .findCreditsRecord(microcredits, searchParameters) ⇒
Promise.<OwnedRecord> - .findCreditsRecords(microcreditAmounts, searchParameters) ⇒
Promise.<OwnedRecord[]> - .findRecord(searchParameters) ⇒
Promise.<OwnedRecord> - .findRecords(searchParameters) ⇒
Promise.<OwnedRecord[]>
- .encryptedRecords(recordsFilter, responseFilter) ⇒
- interface methods
-
NetworkRecordProvider
- constructor
- instance
- .setAccount(account)
- .findCreditsRecords(microcredits, searchParameters) ⇒
Promise.<OwnedRecord[]> - .findCreditsRecord(microcredits, searchParameters) ⇒
Promise.<OwnedRecord> - .findRecord(searchParameters) ⇒
Promise.<OwnedRecord> - .findRecords(searchParameters) ⇒
Promise.<OwnedRecord[]>
-
BlockHeightSearch
Constructor
NetworkRecordProvider
Create a new NetworkRecordProvider instance to find records for program execution and deployment.
new NetworkRecordProvider(account, networkClient)
| Param | Type | Description |
|---|---|---|
| account | Account | The account to use for searching for records |
| networkClient | AleoNetworkClient | The 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[]>
| Parameters | Type | Description |
|---|---|---|
| recordsFilter | RecordSearchParams | The filter used to find the records |
| responseFilter | RecordsResponseFilter | Optional filter used to filter the response |
| return | Promise.<EncryptedRecord[]> | The encrypted records |
checkSerialNumbers
Check if a list of serial numbers exist in the chosen provider.
checkSerialNumbers(serialNumbers) ⇒ Promise.<Record<string, boolean>>
| Parameters | Type | Description |
|---|---|---|
| serialNumbers | string[] | The serial numbers to check |
| return | Promise.<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>>
| Parameters | Type | Description |
|---|---|---|
| tags | string[] | The tags to check |
| return | Promise.<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)
| Parameters | Type | Description |
|---|---|---|
| account | Account | The 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[]>
| Parameters | Type | Description |
|---|---|---|
| microcredits | number[] | The number of microcredits to search for |
| searchParameters | RecordSearchParams | Additional parameters to search for (includes unspent and nonces) |
| return | Promise.<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>
| Parameters | Type | Description |
|---|---|---|
| microcredits | number | The number of microcredits to search for |
| searchParameters | RecordSearchParams | Additional parameters to search for (includes unspent and nonces) |
| return | Promise.<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>
| Parameters | Type | Description |
|---|---|---|
| searchParameters | RecordSearchParams | Parameters to search for |
| return | Promise.<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[]>
| Parameters | Type | Description |
|---|---|---|
| searchParameters | RecordSearchParams | Parameters to search for |
| return | Promise.<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)
| Param | Type | Description |
|---|---|---|
| startHeight | number | The starting block height |
| endHeight | number | The ending block height |
| unspent | boolean | Optional. 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 });