# Aleo JS SDK 中 AleoNetworkClient 的详细介绍 **Published by:** [Yaakov](https://paragraph.com/@yaakov/) **Published on:** 2024-05-16 **URL:** https://paragraph.com/@yaakov/aleo-js-sdk-aleonetworkclient ## Content Aleo JS SDK 中 AleoNetworkClient 的详细介绍AleoNetworkClient 封装了对 Aleo 节点 RPC REST接口的调用,主要提供了对 Aleo 网络中的区块链信息的访问,方便我们直接使用 SDK 访问区块信息。AleoNetworkClientnew AleoNetworkClient(host).setAccount(account).getAccount().getBlock(height).getBlockRange(start, end).getProgram(programId).getProgramMappingNames(programId).getMappingValue(programId, mappingName, key).getLatestBlock().getLatestHash().getLatestHeight().getStateRoot().getTransaction(id).getTransactions(height).getTransactionsInMempool().getTransitionId().findUnspentRecords()new AleoNetworkClient(host)构建 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"); setAccount(account)设置账户,将账户与 client 绑定 Examplelet account = new Account(); connection.setAccount(account); getAccount()返回 client 绑定的账户信息 Examplelet account = connection.getAccount(); getBlock(height)返回指定高度的 block 信息 Examplelet block = connection.getBlock(1234); getBlockRange(start, end)返回指定区块高度区间的区块信息 Examplelet blockRange = connection.getBlockRange(2050, 2100); getProgram(programId)返回程序的源代码,参数为程序 ID, 在 Aleo 中程序的唯一标识就是程序 ID, 并且是唯一的 Examplelet program = connection.getProgram("foo.aleo"); getProgramMappingNames(programId)返回程序对应的 name Examplelet mappings = connection.getProgramMappingNames("credits.aleo"); getMappingValue(programId, mappingName, key)返回指定程序中指定 Map 中对应 key 的 value 值 Example## Get public balance of an account let mappingValue = connection.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px"); getLatestBlock()返回最新的区块信息 Examplelet latestHeight = connection.getLatestBlock(); getLatestHash()返回最新区块的 hashlet latestHash = connection.getLatestHash(); getLatestHeight()返回最新的区块高度 Examplelet latestHeight = connection.getLatestHeight(); getStateRoot()返回最新的 state root Examplelet stateRoot = connection.getStateRoot(); getTransaction(id)返回指定交易 hash 对应的交易 Examplelet transaction = connection.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj"); getTransactions(height)返回指定区块高度对应的所有交易信息 Examplelet transactions = connection.getTransactions(654); getTransactionsInMempool()返回内存池中的交易 Examplelet transactions = connection.getTransactionsInMempool(); getTransitionId(id)返回指定 id 的 transition Examplelet transition = connection.getTransitionId("2429232855236830926144356377868449890830704336664550203176918782554219952323field"); findUnspentRecords()尝试查找指定账户下面的未花费的 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 官方链接:Aleo TwitterAleo DiscordAleo WebsiteAleo Github ## Publication Information - [Yaakov](https://paragraph.com/@yaakov/): Publication homepage - [All Posts](https://paragraph.com/@yaakov/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@yaakov): Subscribe to updates - [Twitter](https://twitter.com/yaakov90691264): Follow on Twitter