I am trying to get the basic info shown in the near wallet using near API.
I want to fetch the info regarding stake and staking reward, basically all the info like:-
I am able to get the stacked near amount but not getting Reward earned
, Pending release
, and Available for withdrawal
I tried these APIs
https://docs.near.org/api/rpc/contracts
https://docs.near.org/tools/near-api-js/contract
async function getAccountBalance(accountId) {
const near = await connect(config);
const protocolConfig = await near.connection.provider.experimental_protocolConfig({ finality: 'final' });
let state = await near.connection.provider.query({
request_type: 'view_account',
account_id: accountId,
finality: 'optimistic'
});
const costPerByte = new bn_js_1.default(protocolConfig.runtime_config.storage_amount_per_byte);
console.log(formatNearAmount(costPerByte));
const stateStaked = new bn_js_1.default(state.storage_usage).mul(costPerByte);
console.log(formatNearAmount(stateStaked));
const staked = new bn_js_1.default(state.locked);
console.log(formatNearAmount(staked));
const totalBalance =await new bn_js_1.default(state.amount).add(staked);
console.log(formatNearAmount(totalBalance));
const availableBalance = totalBalance.sub(bn_js_1.default.max(staked, stateStaked));
console.log(formatNearAmount(availableBalance));
console.log("Storage cost - total balance ---? ", formatNearAmount(availableBalance));
}