I'm currently looking for a way to track delegator activity for any particular validator. I'd like to run this locally and use some form of API/RPC call to access the data. Basically, I don't necessarily want to rely on going to SolanaBeach every time and manually searching for delegator information. Other protocols have this functionality where you can make a query at the latest block height and check delegator information for a particular validator.
2 Answers
Solution: docs.solana.com/cli/usage#solana-stakes
Call the Solana CLI command to access the staking information for delegators.
//stake account is owned by the stake program which runs the complex transactions requried to facilitate staking.
const { Connection, clusterApiUrl, PublicKey } = require("@solana/web3.js");
const getDelegators = async () => {
// establish the connection with solana
const connection = new Connection(clusterApiUrl("devnet"), "processed");
// we have to interact with StakeProgram manually
// https://docs.solana.com/developing/runtime-facilities/programs
const STAKE_PROGRAM_ID = new PublicKey(
"Stake11111111111111111111111111111111111111"
);
const VALIDATOR_PUB_KEY = "******************************";
// STAKE ACCounts are owned by the stake program
const accounts = await connection.getParsedProgramAccounts(STAKE_PROGRAM_ID, {
filters: [
{ dataSize: 200 },
{
// "memory comparison" filter, allows us to compare data at any field stored on our account. Specifically, we can query only for accounts that match a particular set of bytes at a particular position.
memcmp: {
//offset: number - Number of bytes into account data to begin returning
offset: 124,
bytes: VALIDATOR_PUB_KEY,
},
},
],
});
console.log("DELEGATORS ARRAY ", accounts);
};
-
Isn't your VALIDATOR_PUB_KEY larger than 128 bytes and so you hit this error? docs.rs/solana-core/1.5.14/src/solana_core/rpc.rs.html#1590– EliotCommented Oct 27, 2022 at 11:42