• Fetches an array of MaybeAccount | MaybeAccounts from a provided RPC client and an array of addresses.

    It uses the GetMultipleAccountsApi#getMultipleAccounts | getMultipleAccounts RPC method under the hood with the jsonParsed encoding. It may also return a MaybeEncodedAccount instead of the expected MaybeAccount if the RPC client does not know how to parse some of the requested accounts. In any case, the array of expected data types should be explicitly provided as the first type parameter.

    Type Parameters

    • TData extends object[]

      The expected types of these accounts' data.

    • TAddresses extends string[] = string[]

      Supply an array of string literals to define accounts having particular addresses.

    • TWrappedAddresses extends {
          [P in string | number | symbol]: Address<TAddresses[P<P>]>
      } = {
          [P in string | number | symbol]: Address<TAddresses[P<P>]>
      }

    Parameters

    Returns Promise<{
        [P in keyof TAddresses]: {
            address: Address<TAddresses[P]>;
            exists: false;
        } | BaseAccount & {
            address: Address<TAddresses[P]>;
            data: TData[P & keyof (...)] & {
                parsedAccountMeta?: {
                    program: string;
                    type?: string;
                };
            };
        } & {
            exists: true;
        } | BaseAccount & {
            address: Address<TAddresses[P]>;
            data: Uint8Array<ArrayBufferLike>;
        } & {
            exists: true;
        }
    } & {
        [P_1 in keyof TData]: {
            address: Address<TAddresses[P_1 & keyof TAddresses]>;
            exists: false;
        } | BaseAccount & {
            address: Address<TAddresses[P_1 & keyof (...)]>;
            data: TData[P_1] & {
                parsedAccountMeta?: {
                    program: string;
                    type?: string;
                };
            };
        } & {
            exists: true;
        } | BaseAccount & {
            address: Address<TAddresses[P_1 & keyof (...)]>;
            data: Uint8Array<ArrayBufferLike>;
        } & {
            exists: true;
        }
    }>

    type TokenData = { mint: Address; owner: Address };
    type MintData = { supply: bigint };
    const [myAccountA, myAccountB] = await fetchJsonParsedAccounts<[TokenData, MintData]>(rpc, [myAddressA, myAddressB]);
    myAccountA satisfies MaybeAccount<TokenData> | MaybeEncodedAccount;
    myAccountB satisfies MaybeAccount<MintData> | MaybeEncodedAccount;