3

假设我们像这样初始化并且用户已经登录:

    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(...)
4

1 回答 1

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
}
于 2019-09-12T17:18:26.910 回答