2

I want to receive all staking accounts for a wallet. How can I do this? I'm trying to use getParsedProgramAccounts, but don't know what should I put for data size and offset

 const accounts = await connection.getParsedProgramAccounts(
      STAKE_PROGRAM_ID,
      {
        filters: [
          {
            dataSize: 200, // number of bytes
          },
          {
            memcmp: {
              offset: 64, // number of bytes
              bytes: WALLET_KEY, // base58 encoded string
            },
          },
        ],
      },
    );

2 Answers 2

2

dataSize here seems redundant. And for offset you should use 12

Result:

const accounts = await connection.getParsedProgramAccounts(
      STAKE_PROGRAM_ID,
      {
        filters: [
          {
            memcmp: {
              offset: 12, // number of bytes
              bytes: WALLET_KEY, // base58 encoded string
            },
          },
        ],
      },
    );
1
  • Thanks, that worked for me. Where did you get the offset of 12 from? Commented Nov 23, 2023 at 2:20
1

Staking account is a Token Account so you can use the "getTokenAccountsByOwner" from Solana JSON RPC call : https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountsbyowner

1
  • After call I recieve exception: failed to get token accounts owned by account F8dQyDCkxKtgoNi8QGJ2qyDGcRnzzy15BzmCb4JoPdaR: Invalid param: unrecognized Token program id at Connection.getTokenAccountsByOwner programId is Stake11111111111111111111111111111111111111 getTokenAccountsByOwner(new PublicKey('F8dQyDCkxKtgoNi8QGJ2qyDGcRnzzy15BzmCb4JoPdaR'), { programId: new PublicKey( 'Stake11111111111111111111111111111111111111', ), });
    – Oksana
    Commented Oct 6, 2022 at 11:35

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.