我是区块链开发的新手,正在使用Algorand的JS SDK。是否可以通过地址检索钱包中的所有资产?
谢谢
您可以使用来自algord(节点的algo守护进程(或索引器(Postgres数据库(的端点来获取这些信息。
Algod方法:
const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
const accountInfo = await algodClient.accountInformation(address).do();
https://algorand.github.io/js-algorand-sdk/classes/Algodv2.html#accountInformation
索引器方法:
const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
const accountAssets = await indexerClient.lookupAccountAssets(address).do();
https://algorand.github.io/js-algorand-sdk/classes/Indexer.html#lookupAccountAssets
出于演示目的,我只是从Algoexplorer中随机找到了一个地址。
const token = "";
const port = "";
const algodServer = "https://mainnet-api.algonode.cloud";
const indexerServer = "https://mainnet-idx.algonode.cloud";
const algodClient = new algosdk.Algodv2(token, algodServer, port);
const indexerClient = new algosdk.Indexer(token, indexerServer, port);
(async () => {
const address = "A4YW55ZEC2TTIN2TEVN56IRVGLWQYQRUNJTPG37OTWE4EJWNAH3EUKHZKA";
const algodAccountAssets = await algodClient.accountInformation(address).do();
const indexerAccountAssets = await indexerClient.lookupAccountAssets(address).do();
console.log("algod results: ", algodAccountAssets)
console.log("indexer results: ", indexerAccountAssets)
})();
<script src="https://unpkg.com/algosdk@v1.18.1/dist/browser/algosdk.min.js"></script>
是的,您可以使用这个:GET /v2/accounts/{address}
这将返回一个assets
数组,以及其他一些东西——您可以在此处阅读更多内容。