Advertisement
_chalda

Solana stake account HTTP getProgramAccounts

Jan 6th, 2025
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 1.00 KB | Cryptocurrency | 0 0
  1. export const getStakeAccounts = async (connection: Connection, withdrawAuthority: PublicKey | null, stakeAuthority: PublicKey | null): Promise<{
  2.     pubkey: PublicKey;
  3.     account: AccountInfo<ParsedAccountData>;
  4. }[]> => {
  5.     if (!stakeAuthority && !withdrawAuthority) {
  6.         throw new Error('At least one authority must be provided')
  7.     }
  8.  
  9.     const filters: GetProgramAccountsFilter[] = []
  10.     if (stakeAuthority) {
  11.         filters.push({
  12.             memcmp: {
  13.                 bytes: stakeAuthority.toBase58(),
  14.                 offset: 4 + 8
  15.             }
  16.         })
  17.     }
  18.     if (withdrawAuthority) {
  19.         filters.push({
  20.             memcmp: {
  21.                 bytes: withdrawAuthority.toBase58(),
  22.                 offset: 4 + 8 + 32
  23.             }
  24.         })
  25.     }
  26.  
  27.     const stakeAccounts = await connection.getParsedProgramAccounts(StakeProgram.programId, { filters })
  28.  
  29.     return stakeAccounts as {
  30.         pubkey: PublicKey;
  31.         account: AccountInfo<ParsedAccountData>;
  32.     }[]
  33. }
Tags: solana
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement