1

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
  • I found a command in the CLI: docs.solana.com/cli/usage#solana-stakes. Seems to be returning delegate information for a provided validator pubkey.
    – Popski
    Commented Jul 22, 2022 at 15:05
  • please post solutions as answers, not comments
    – trent.sol
    Commented Jul 22, 2022 at 21:05

2 Answers 2

2

Solution: docs.solana.com/cli/usage#solana-stakes

Call the Solana CLI command to access the staking information for delegators.

2
//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);
};
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.