Aleo Network Client
Overview
Connection management class that encapsulates REST calls to publicly exposed endpoints of Aleo nodes. The methods provided in this class provide information on the Aleo Blockchain
Kind: global class
- AleoNetworkClient
- new AleoNetworkClient(host)
- .setAccount(host)
- .setAccount(account)
- .getAccount()
- .getBlock(height)
- .getBlockRange(start, end)
- .getProgram(programId)
- .getProgramObject(programId)
- .getProgramImports(programId)
- .getDeploymentTransactionIDForProgram(programId)
- .getDeploymentTransactionForProgram(programId)
- .getProgramMappingNames(programId)
- .getMappingValue(programId, mappingName, key)
- .getLatestBlock()
- .getLatestHeight()
- .getStateRoot()
- .getTransaction(id)
- .getTransactions(height)
- .getTransactionsInMempool()
- .getTransitionId()
- .findUnspentRecords()
new AleoNetworkClient(host)
Param | Type |
---|---|
host | string |
Example
// Connection to a local node
let local_connection = new AleoNetworkClient("http://localhost:3030");
// Connection to a public beacon node
let public_connection = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
aleoNetworkClient.setHost(host)
Set a new host for the networkClient
Param | Type |
---|---|
host | string |
Example
// New connection to a public beacon node
let public_connection = AleoNetworkClient.setHost("https://api.explorer.aleo.org/v1");
aleoNetworkClient.setAccount(account)
Set an account
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
account | Account |
Example
let account = new Account();
connection.setAccount(account);
aleoNetworkClient.getAccount()
Return the Aleo account used in the node connection
Kind: instance method of AleoNetworkClient
Example
let account = connection.getAccount();
aleoNetworkClient.getBlock(height)
Returns the block contents of the block at the specified block height
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
height | number |
Example
let block = connection.getBlock(1234);
aleoNetworkClient.getBlockRange(start, end)
Returns a range of blocks between the specified block heights
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
start | number |
end | number |
Example
let blockRange = connection.getBlockRange(2050, 2100);
aleoNetworkClient.getProgram(programId)
Returns the source code of a program
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
programId | string |
Example
let program = connection.getProgram("foo.aleo");
aleoNetworkClient.getProgramObject(programId)
Returns a program object from a program ID or program source code
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
programId | string |
Example
let program = connection.getProgramObject("foo.aleo");
aleoNetworkClient.getProgramImports(programId)
Returns an object containing the source code of a program and the source code of all programs it imports
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
programId | string |
Example
let program = connection.getProgramImports("foo.aleo");
aleoNetworkClient.getDeploymentTransactionIDForProgram(programId)
Returns the deployment transaction id associated with the specified program
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
programId | string |
Example
let program = connection.getDeploymentTransactionIDForProgram("foo.aleo");
aleoNetworkClient.getDeploymentTransactionForProgram(programId)
Returns the deployment transaction associated with a specified program
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
programId | string |
Example
let program = connection.getDeploymentTransactionForProgram("foo.aleo");
aleoNetworkClient.getProgramMappingNames(programId)
Returns the names of the mappings of a program
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
programId | string |
Example
let mappings = connection.getProgramMappingNames("credits.aleo");
aleoNetworkClient.getProgramImportNames(programId)
Get a list of the program names that a program imports
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
programId | string |
Example
let mappings = connection.getProgramImportNames("foo.aleo");
aleoNetworkClient.getMappingValue(programId, mappingName, key)
Returns the value of a program's mapping for a specific key
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
programId | string |
mappingName | string |
key | string |
Example
## Get public balance of an account
let mappingValue = connection.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
aleoNetworkClient.getLatestBlock()
Returns the block contents of the latest block
Kind: instance method of AleoNetworkClient
Example
let latestHeight = connection.getLatestBlock();
aleoNetworkClient.getLatestHeight()
Returns the latest block height
Kind: instance method of AleoNetworkClient
Example
let latestHeight = connection.getLatestHeight();
aleoNetworkClient.getLatestCommittee()
Returns the latest committee
Kind: instance method of AleoNetworkClient
Example
let latestCommittee = connection.getLatestCommittee();
aleoNetworkClient.getStateRoot()
Returns the latest state/merkle root of the Aleo blockchain
Kind: instance method of AleoNetworkClient
Example
let stateRoot = connection.getStateRoot();
aleoNetworkClient.getTransaction(id)
Returns a transaction by its unique identifier
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
id | string |
Example
let transaction = connection.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
aleoNetworkClient.getTransactions(height)
Returns the transactions present at the specified block height
Kind: instance method of AleoNetworkClient
Param | Type |
---|---|
height | number |
Example
let transactions = connection.getTransactions(654);
aleoNetworkClient.getTransactionsInMempool()
Returns the transactions in the memory pool.
Kind: instance method of AleoNetworkClient
Example
let transactions = connection.getTransactionsInMempool();
aleoNetworkClient.getTransitionId()
Returns the transition id by its unique identifier
Kind: instance method of AleoNetworkClient
Example
let transition = connection.getTransitionId("2429232855236830926144356377868449890830704336664550203176918782554219952323field");
aleoNetworkClient.findUnspentRecords()
Attempts to find unspent records in the Aleo blockchain for a specified private key
Kind: instance method of AleoNetworkClient
Example
// Find all unspent records
const privateKey = "[PRIVATE_KEY]";
let records = connection.findUnspentRecords(0, undefined, privateKey);
// Find specific amounts
const startHeight = 500000;
const amounts = [600000, 1000000];
let records = connection.findUnspentRecords(startHeight, undefined, privateKey, amounts);
// Find specific amounts with a maximum number of cumulative microcredits
const maxMicrocredits = 100000;
let records = connection.findUnspentRecords(startHeight, undefined, privateKey, undefined, maxMicrocredits);