You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过NEAR API获取钱包质押收益、待释放等核心信息

问题:获取NEAR钱包质押及奖励相关数据

我需要通过NEAR API获取NEAR钱包展示的基本信息,核心是质押及质押奖励类数据,包括:

  • 已赚取奖励(Reward earned)
  • 待释放金额(Pending release)
  • 可提取金额(Available for withdrawal)

目前我已经能获取质押的NEAR数量,但无法获取上述三类数据。我参考过NEAR的RPC合约相关文档和near-api-js的合约工具文档,编写了如下代码:

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 = 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));
}

内容的提问来源于stack exchange,提问作者Mohit Chandel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 21:45:28