Skip to main content

Record Scanner

Overview

A record provider implementation that uses a record scanning service to find records for usage in program execution and deployment, wallet functionality, and other use cases. This is an alternative to NetworkRecordProvider for users who prefer to use a dedicated scanning service.

Kind: global class

Constructor

RecordScanner

Create a new RecordScanner instance that uses a record scanning service to find records.

new RecordScanner(options)
ParamTypeDescription
optionsRecordScannerOptionsConfiguration options for the record scanner

RecordScannerOptions

PropertyTypeDescription
urlstringThe URL of the record scanning service
apiKeystring | { header: string, value: string }Optional API key for authentication

Example

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

// Create a new RecordScanner with a simple API key
const recordScanner = new RecordScanner({
url: "https://record-scanner.aleo.org",
apiKey: "your-api-key"
});

// Or with a custom header
const recordScannerCustomHeader = new RecordScanner({
url: "https://record-scanner.aleo.org",
apiKey: { header: "X-Custom-Header", value: "your-api-key" }
});

// Register an account and start scanning
const account = new Account({ privateKey: 'APrivateKey1...' });
const response = await recordScanner.register(account.viewKey(), 0);

// Find records
const filter = {
uuid: response.uuid,
filter: {
program: "credits.aleo",
records: ["credits"],
},
unspent: true,
};
const records = await recordScanner.findRecords(filter);

RecordScanner Methods

setApiKey

Set the API key to use for the record scanner.

setApiKey(apiKey)Promise.<void>
ParametersTypeDescription
apiKeystring | &#123; header: string, value: string &#125;The API key to use for the record scanner
returnPromise.<void>Resolves when the API key is set

Example

// Set API key as a string (uses default header X-Provable-API-Key)
await recordScanner.setApiKey("your-api-key");

// Set API key with a custom header
await recordScanner.setApiKey({ header: "X-Custom-Header", value: "your-api-key" });

setUuid

Set the UUID to use for the record scanner. The UUID identifies the registered account with the scanning service.

setUuid(uuidOrViewKey)Promise.<void>
ParametersTypeDescription
uuidOrViewKeyField | ViewKeyThe UUID or ViewKey to use for the record scanner
returnPromise.<void>Resolves when the UUID is set

Example

// Set UUID directly
await recordScanner.setUuid(uuidField);

// Or compute UUID from ViewKey
await recordScanner.setUuid(account.viewKey());

register

Register the account with the record scanner service. This must be called before finding records.

register(viewKey, startBlock)Promise.<RegistrationResponse>
ParametersTypeDescription
viewKeyViewKeyThe view key of the account to register
startBlocknumberThe block height to start scanning from
returnPromise.<RegistrationResponse>The response from the record scanner service containing the UUID

Example

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

const account = new Account({ privateKey: 'APrivateKey1...' });
const recordScanner = new RecordScanner({ url: "https://record-scanner.aleo.org" });

// Register the account starting from block 0
const response = await recordScanner.register(account.viewKey(), 0);
console.log("Registration UUID:", response.uuid);

encryptedRecords

Get encrypted records from the record scanner service.

encryptedRecords(recordsFilter)Promise.<EncryptedRecord[]>
ParametersTypeDescription
recordsFilterRecordsFilterThe filter to use to find the records and filter the response
returnPromise.<EncryptedRecord[]>Array of encrypted records matching the filter

Example

const filter = {
uuid: "your-uuid",
filter: {
program: "credits.aleo",
records: ["credits"],
},
};
const encryptedRecords = await recordScanner.encryptedRecords(filter);

checkSerialNumbers

Check if a list of serial numbers exist in the record scanner service. This is used to determine if records have been spent.

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.

Example

const serialNumbers = ["sn1...", "sn2..."];
const result = await recordScanner.checkSerialNumbers(serialNumbers);
console.log(result); // { "sn1...": true, "sn2...": false }

checkTags

Check if a list of tags exist in the record scanner service. This is used to determine if records have been spent.

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.

Example

const tags = ["tag1...", "tag2..."];
const result = await recordScanner.checkTags(tags);
console.log(result); // { "tag1...": false, "tag2...": true }

checkStatus

Check the status of a record scanner indexing job.

checkStatus()Promise.<StatusResponse>
ParametersTypeDescription
returnPromise.<StatusResponse>The status of the indexing job for the registered account

Example

const status = await recordScanner.checkStatus();
console.log("Current block:", status.current_block);
console.log("Indexed up to:", status.indexed_to);

findRecord

Find a single record in the record scanner service.

findRecord(searchParameters)Promise.<OwnedRecord>
ParametersTypeDescription
searchParametersOwnedFilterThe filter to use to find the record
returnPromise.<OwnedRecord>The first record matching the filter

Example

const filter = {
decrypt: true,
unspent: true,
filter: {
program: "credits.aleo",
record: "credits",
},
};
const record = await recordScanner.findRecord(filter);

findRecords

Find multiple records in the record scanner service.

findRecords(filter)Promise.<OwnedRecord[]>
ParametersTypeDescription
filterOwnedFilterThe filter to use to find the records
returnPromise.<OwnedRecord[]>Array of records matching the filter

Example

const filter = {
decrypt: true,
unspent: true,
filter: {
program: "credits.aleo",
record: "credits",
},
responseFilter: {
commitment: true,
owner: true,
tag: true,
spent: true,
record_ciphertext: true,
block_height: true,
block_timestamp: true,
},
};
const records = await recordScanner.findRecords(filter);
console.log(`Found ${records.length} records`);

findCreditsRecord

Find a credits record with at least the specified number of microcredits.

findCreditsRecord(microcredits, searchParameters)Promise.<OwnedRecord>
ParametersTypeDescription
microcreditsnumberThe minimum amount of microcredits to find
searchParametersOwnedFilterThe filter to use to find the record
returnPromise.<OwnedRecord>A credits record with at least the specified microcredits

Example

// Find a credits record with at least 1,000,000 microcredits (1 credit)
const record = await recordScanner.findCreditsRecord(1000000, {
unspent: true,
filter: { start: 0 },
});
console.log("Found record:", record.record_plaintext);

findCreditsRecords

Find credits records matching specific microcredit amounts.

findCreditsRecords(microcreditAmounts, searchParameters)Promise.<OwnedRecord[]>
ParametersTypeDescription
microcreditAmountsnumber[]The amounts of microcredits to find
searchParametersOwnedFilterThe filter to use to find the records
returnPromise.<OwnedRecord[]>Array of credits records matching the specified amounts

Example

// Find credits records with specific amounts
const amounts = [1000000, 5000000, 10000000];
const records = await recordScanner.findCreditsRecords(amounts, {
unspent: true,
filter: { start: 0 },
});
console.log(`Found ${records.length} matching records`);

computeUUID

Compute the UUID for a given view key. This is used internally to identify accounts with the scanning service.

computeUUID(vk)Field
ParametersTypeDescription
vkViewKeyThe view key to compute the UUID for
returnFieldThe computed UUID as a Field element

Example

const uuid = recordScanner.computeUUID(account.viewKey());
console.log("Computed UUID:", uuid.toString());

OwnedFilter Interface

The OwnedFilter interface defines the search parameters for finding owned records.

PropertyTypeDescription
uuidstringOptional. The UUID identifying the registered account
decryptbooleanOptional. Whether to decrypt the records
unspentbooleanOptional. Whether to filter for unspent records only
filterobjectOptional. Filter criteria for the records
filter.startnumberOptional. Starting block height
filter.programstringOptional. Program ID to filter by
filter.recordstringOptional. Record name to filter by
responseFilterOwnedRecordsResponseFilterOptional. Fields to include in the response

OwnedRecordsResponseFilter Interface

The OwnedRecordsResponseFilter interface defines which fields to include in the record response.

PropertyTypeDescription
commitmentbooleanInclude the record commitment
ownerbooleanInclude the record owner
tagbooleanInclude the record tag
senderbooleanInclude the sender address
spentbooleanInclude spent status
record_ciphertextbooleanInclude the encrypted record
block_heightbooleanInclude the block height
block_timestampbooleanInclude the block timestamp
output_indexbooleanInclude the output index
record_namebooleanInclude the record name
function_namebooleanInclude the function name
program_namebooleanInclude the program name
transition_idbooleanInclude the transition ID
transaction_idbooleanInclude the transaction ID
transaction_indexbooleanInclude the transaction index
transition_indexbooleanInclude the transition index