getAccountMetaFactory
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:
- 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. - Otherwise, if the value is a TransactionSigner and the account's
isSignerflag is notfalse, the IDL's writable flag is upgraded to the corresponding signer role and the signer is attached to the meta. WhenisSignerisfalse, the signer merely acts as an address carrier and no upgrade occurs. Omitting the flag is equivalent to'either'. - Otherwise, the IDL's writable flag decides between the readonly and writable roles.
Parameters
| Parameter | Type | Description |
|---|---|---|
programAddress | Address | The 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.