Reputation: 193
How to retrieve "total amount staked" and "rewards earned" for a particular Near staking account? Ideally via an API.
Upvotes: 0
Views: 636
Reputation: 5693
Call an archival rpc node on the staking pool smart contract with method_name get_account_total_balance
, which will give you the staked amount.
example:
fetch('https://archival-rpc.mainnet.near.org', {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
'jsonrpc': '2.0',
'id': 'dontcare',
'method': 'query',
'params': {
request_type: 'call_function',
//finality: 'final',
block_id: block_id,
account_id: stakingpool_id,
method_name: 'get_account_total_balance',
args_base64: btoa(JSON.stringify({
account_id: account_id
}))
}
})
In order to get the rewards earned, look at the balance for previous epochs ( every 12 hour ) and calculate the difference.
Upvotes: 0