Reputation: 600
Is there a way to query the NEAR RPC for all current delegators of a specific validator? I checked the API docs, can't find something like this but seems like an essential function that has to exist.
Upvotes: 2
Views: 185
Reputation: 600
Thanks to Vlad Frolov's answer here's an example implementation in JS.
fetch("https://rpc.<CHAIN_ID>.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",
"account_id": <ACCOUNT_ID>,
"method_name": "get_accounts",
"args_base64": btoa(JSON.stringify({
"from_index": 0,
"limit": 100
}))
}
})
})
.then((response) => response.json())
.then((data) => {
const result = JSON.parse(String.fromCharCode(...data.result.result))
console.log(result)
})
Upvotes: 1
Reputation: 7756
"Delegators" is a staking pool contract concept, so you need to make a view-function call to the staking pool contract, specifically, call get_accounts()
function
NEAR RPC query
method has call_function
request type which is used to make view-function calls.
Upvotes: 1