我对blockchain很陌生,并且正在为Algorand使用JS。是否可以通过一个钱包的地址来取回钱包中的所有资产?
谢谢
发布于 2022-07-20 15:33:12
您可以使用algod (节点的algo守护进程)或indexer (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>
发布于 2022-07-20 14:07:41
是的,你可以用这个:GET /v2/accounts/{address}
这将返回一个assets数组,以及其他一些东西--您可以读取更多的这里。
https://stackoverflow.com/questions/73053143
复制相似问题