如何使用 Nearlib.js 获取特定帐户的余额
How to get certain acount's balance using Nearlib.js
假设我们像这样初始化 near 并且用户已经登录:
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
class 中。以下是查询您自己的帐户信息的方法:
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
}
假设我们像这样初始化 near 并且用户已经登录:
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
class 中。以下是查询您自己的帐户信息的方法:
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
}