假设我们像这样初始化并且用户已经登录:
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(...)
答案 0 :(得分:6)
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
}