AleoNetworkClient 封装了对 Aleo 节点 RPC REST接口的调用,主要提供了对 Aleo 网络中的区块链信息的访问,方便我们直接使用 SDK 访问区块信息。
AleoNetworkClient
构建 AleoNetworkClient 的实例,参数为节点的 rpc
Example
// Connection to a local node
let connection = new AleoNetworkClient("http://localhost:3030");
// Connection to a public beacon node
let connection = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
设置账户,将账户与 client 绑定
Example
let account = new Account();
connection.setAccount(account);
返回 client 绑定的账户信息
Example
let account = connection.getAccount();
返回指定高度的 block 信息
Example
let block = connection.getBlock(1234);
返回指定区块高度区间的区块信息
Example
let blockRange = connection.getBlockRange(2050, 2100);
返回程序的源代码,参数为程序 ID, 在 Aleo 中程序的唯一标识就是程序 ID, 并且是唯一的
Example
let program = connection.getProgram("foo.aleo");
返回程序对应的 name
Example
let mappings = connection.getProgramMappingNames("credits.aleo");
返回指定程序中指定 Map 中对应 key 的 value 值
Example
## Get public balance of an account
let mappingValue = connection.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
返回最新的区块信息
Example
let latestHeight = connection.getLatestBlock();
返回最新区块的 hash
let latestHash = connection.getLatestHash();
返回最新的区块高度
Example
let latestHeight = connection.getLatestHeight();
返回最新的 state root
Example
let stateRoot = connection.getStateRoot();
返回指定交易 hash 对应的交易
Example
let transaction = connection.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
返回指定区块高度对应的所有交易信息
Example
let transactions = connection.getTransactions(654);
返回内存池中的交易
Example
let transactions = connection.getTransactionsInMempool();
返回指定 id 的 transition
Example
let transition = connection.getTransitionId("2429232855236830926144356377868449890830704336664550203176918782554219952323field");
尝试查找指定账户下面的未花费的 Records
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);
Aleo 官方链接:
