在Solana中,您可以使用CLI实现自己的平衡
$ spl-token accounts但是,如果我有帐户ID或他的公钥,我如何获得国外帐户的令牌余额?当我使用solana explorer时,我可以看到我需要的信息,当我搜索外国帐户ID,然后单击令牌选项卡(旁边的“历史”):https://explorer.solana.com/address/DNuqHBGxzm96VLkLWCUctjYW9CX68DBY6jQ1cVuYP2Ai/tokens?cluster=devnet
因此,如果资源管理器网站可以做到这一点,每个人都可以做到,区块链上的所有信息都是公开的,对吧?
发布于 2021-10-19 21:28:49
没错,所有的东西都是公开的,所以如果你想获取别人账户的余额,你可以简单地使用getBalance (如果是SOL (https://docs.solana.com/developing/clients/jsonrpc-api#getbalance) )或者getTokenAccountBalance (如果是SPL令牌账户(https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountbalance) )。
发布于 2021-10-20 17:48:08
下面的代码在Jon Cinque的回答之后得到了SOL的平衡(可能对其他人或未来的我有帮助):
const web3 = require("@solana/web3.js");
const { Keypair, Transaction, SystemProgram, LAMPORTS_PER_SOL, sendAndConfirmTransaction, clusterApiUrl } = require("@solana/web3.js");
let secretKey = Uint8Array.from([233, 65, ... (rest of my secret)]);
let fromKeypair = Keypair.fromSecretKey(secretKey);
let connection = new web3.Connection(clusterApiUrl('devnet'));
(async () => {
const balance = await connection.getBalance(
fromKeypair.publicKey
);
console.log(balance)
})()输出:7912350560,这是正确的,因为我有7.912350560索尔在该帐户。
但是对于SPL令牌,它还不能工作...
https://stackoverflow.com/questions/69636415
复制相似问题