getAccountMetaFactory

function getAccountMetaFactory(
    programAddress,
    optionalAccountStrategy,
): (
    inputName,
    account,
) =>
    | AccountMeta<string>
    | AccountSignerMeta<string, TransactionSigner<string>>
    | undefined;

Creates a factory function that converts resolved instruction accounts to account metas.

The factory handles the conversion of ResolvedInstructionAccount objects into AccountMeta or AccountSignerMeta objects suitable for building instructions. It also determines how to handle optional accounts based on the provided strategy.

The role of the resulting account meta is determined as follows, in order of precedence:

  1. If the value carries an explicit role — i.e. it is an AccountNonSignerMeta or an AccountSignerMeta — that role is used as-is, regardless of the flags declared by the program's IDL.
  2. Otherwise, if the value is a TransactionSigner and the account's isSigner flag is not false, the IDL's writable flag is upgraded to the corresponding signer role and the signer is attached to the meta. When isSigner is false, the signer merely acts as an address carrier and no upgrade occurs. Omitting the flag is equivalent to 'either'.
  3. Otherwise, the IDL's writable flag decides between the readonly and writable roles.

Parameters

ParameterTypeDescription
programAddressAddressThe program address, used when optional accounts use the programId strategy.
optionalAccountStrategy"omitted" | "programId"How to handle null account values: - 'omitted': Optional accounts are excluded from the instruction entirely. - 'programId': Optional accounts are replaced with the program address as a read-only account.

Returns

A factory function that converts a resolved account to an account meta.

(inputName, account) => | AccountMeta<string> | AccountSignerMeta<string, TransactionSigner<string>> | undefined

Throws

Throws a SolanaError when the account's isSigner flag is true but the provided value is neither a TransactionSigner nor carries an explicit role. Use createNoopSigner() from @solana/signers if the account's signature is provided by other means.

Example

const toAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const mintMeta = toAccountMeta('mint', resolvedMint);

On this page