假设我们像这样初始化,并且用户已经登录:
const near = await window.nearlib.connect(Object.assign({ deps: { keyStore: new window.nearlib.keyStores.BrowserLocalStorageKeyStore() } }, window.nearConfig));
const walletAccount = new window.nearlib.WalletAccount(near);
我希望能够使用以下内容获取帐户的 NEAR 余额:
near.getBalanceOf(walletAccount.getAccountId()).then(...)
或者可能
walletAccount.getBalance().then(...)
最佳答案
WalletAccount
只是用来登录钱包。所有相关的 API 都位于 Account
类中。以下是查询您自己的帐户信息的方法:
let account = await near.account(walletAccount.getAccountId());
console.log(await account.state());
结果将是这样的:
{
"amount":"20999000097842111450",
"code_hash":"11111111111111111111111111111111",
"staked":"2000000000",
"storage_paid_at":324708,
"storage_usage":551
}
关于nearprotocol - 如何使用 Nearlib.js 获得某个账户的余额,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57904464/