Kit
Functions

addSignersToInstruction

addSignersToInstruction<TInstruction>(signers, instruction): InstructionWithSigners & TInstruction

Attaches the provided TransactionSigners to the account metas of an instruction when applicable.

For an account meta to match a provided signer it:

  • Must have a signer role (AccountRole.READONLY_SIGNER or AccountRole.WRITABLE_SIGNER).
  • Must have the same address as the provided signer.
  • Must not have an attached signer already.

Type Parameters

Type ParameterDescription
TInstruction extends Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>The inferred type of the instruction provided.

Parameters

ParameterType
signersTransactionSigner[]
instructionTInstruction | InstructionWithSigners & TInstruction

Returns

InstructionWithSigners & TInstruction

Example

import { AccountRole, Instruction } from '@solana/instructions';
import { addSignersToInstruction, TransactionSigner } from '@solana/signers';
 
const instruction: Instruction = {
    accounts: [
        { address: '1111' as Address, role: AccountRole.READONLY_SIGNER },
        { address: '2222' as Address, role: AccountRole.WRITABLE_SIGNER },
    ],
    // ...
};
 
const signerA: TransactionSigner<'1111'>;
const signerB: TransactionSigner<'2222'>;
const instructionWithSigners = addSignersToInstruction(
    [signerA, signerB],
    instruction
);
 
// instructionWithSigners.accounts[0].signer === signerA
// instructionWithSigners.accounts[1].signer === signerB

On this page