Skip to Content
DocumentationData AccountsGet Accounts

Get Accounts

The getAccountsFactory function creates a function (called get(Something)Accounts) that gets all program accounts of a particular type. Accounts will be decoded, so you can see the actual values for each of the fields inside. Useful for getting all offers, auctions, or users from a program.

You might notice this is one of the only factory functions you need to explicitly use in Kite. That’s because it creates a function specifically for an account type from your Solana program.

Usage

// Create a function to get all offers const getOffers = connection.getAccountsFactory( programClient.ESCROW_PROGRAM_ADDRESS, OFFER_DISCRIMINATOR, getOfferDecoder() ); // Use it to get all offers const offers = await getOffers();

Parameters

  • programAddress: Address - The program address to query accounts from
  • discriminator: Uint8Array - The discriminator to filter accounts by
  • decoder: Decoder<T> - The decoder to use for parsing account data

Returns

Returns a function that returns Promise<Array<T>> - A function that returns an array of decoded accounts.

Example

This example shows how to get all offers from an escrow program. The programClient, OFFER_DISCRIMINATOR and getOfferDecoder all come from a generated client made by Codama.

import * as programClient from "../dist/js-client"; import { getOfferDecoder, OFFER_DISCRIMINATOR } from "../dist/js-client"; // Create a function to get all offers const getOffers = connection.getAccountsFactory( programClient.ESCROW_PROGRAM_ADDRESS, OFFER_DISCRIMINATOR, getOfferDecoder() ); // Use it to get all offers const offers = await getOffers();

Understanding Account Factories

Account factories are useful when you need to:

  • Get all accounts of a particular type from a program
  • Decode account data into a structured format
  • Work with multiple accounts of the same type

Common uses include:

  • Getting all offers in an escrow program
  • Getting all auctions in an auction program
  • Getting all users in a user management program
Last updated on