addSignersToTransactionMessage

function addSignersToTransactionMessage<TTransactionMessage>(
    signers,
    transactionMessage,
): Partial<
    Pick<
        | TransactionMessageWithFeePayer<string>
        | TransactionMessageWithFeePayerSigner<
              string,
              TransactionSigner<string>
          >,
        'feePayer'
    >
> &
    Readonly<{
        instructions: readonly Instruction<
            string,
            readonly (
                | AccountLookupMeta<string, string>
                | AccountMeta<string>
            )[]
        > &
            InstructionWithSigners<
                TransactionSigner<string>,
                readonly AccountMetaWithSigner<
                    TransactionSigner<string>
                >[]
            >[];
    }> &
    TTransactionMessage;

Attaches the provided TransactionSigners to the account metas of all instructions inside a transaction message and/or the transaction message fee payer, 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
TTransactionMessage extends Readonly<{ instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[]; }>The inferred type of the transaction message provided.

Parameters

ParameterType
signersTransactionSigner[]
transactionMessageTTransactionMessage

Returns

Partial<Pick< | TransactionMessageWithFeePayer<string> | TransactionMessageWithFeePayerSigner<string, TransactionSigner<string>>, "feePayer">> & Readonly<{ instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]> & InstructionWithSigners<TransactionSigner<string>, readonly AccountMetaWithSigner<TransactionSigner<string>>[]>[]; }> & TTransactionMessage

Example

import { AccountRole, Instruction } from '@solana/instructions';
import { TransactionMessage } from '@solana/transaction-messages';
import { addSignersToTransactionMessage, TransactionSigner } from '@solana/signers';
 
const instructionA: Instruction = {
    accounts: [{ address: '1111' as Address, role: AccountRole.READONLY_SIGNER }],
    // ...
};
const instructionB: Instruction = {
    accounts: [{ address: '2222' as Address, role: AccountRole.WRITABLE_SIGNER }],
    // ...
};
const transactionMessage: TransactionMessage = {
    instructions: [instructionA, instructionB],
    // ...
}
 
const signerA: TransactionSigner<'1111'>;
const signerB: TransactionSigner<'2222'>;
const transactionMessageWithSigners = addSignersToTransactionMessage(
    [signerA, signerB],
    transactionMessage
);
 
// transactionMessageWithSigners.instructions[0].accounts[0].signer === signerA
// transactionMessageWithSigners.instructions[1].accounts[0].signer === signerB

On this page