appendTransactionMessageInstructionPlan

function appendTransactionMessageInstructionPlan<TTransactionMessage>(
    instructionPlan,
    transactionMessage,
): AppendTransactionMessageInstructions<TTransactionMessage>;

Appends all instructions from an instruction plan to a transaction message.

This function flattens the instruction plan into its leaf plans and sequentially appends each instruction to the provided transaction message. It handles both single instructions and message packer plans.

Note that any MessagePackerInstructionPlan is assumed to only append instructions. If it modifies other properties of the transaction message, the type of the returned transaction message may not accurately reflect those changes.

Type Parameters

Type ParameterDescription
TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer<string>The type of transaction message being modified.

Parameters

ParameterTypeDescription
instructionPlanInstructionPlanThe instruction plan containing the instructions to append.
transactionMessageTTransactionMessageThe transaction message to append instructions to.

Returns

AppendTransactionMessageInstructions<TTransactionMessage>

The transaction message with all instructions from the plan appended.

Examples

Appending a simple instruction plan to a transaction message.

import { appendTransactionMessageInstructionPlan } from '@solana/instruction-plans';
import { createTransactionMessage, setTransactionMessageFeePayer } from '@solana/transaction-messages';
 
const message = setTransactionMessageFeePayer(feePayer, createTransactionMessage({ version: 0 }));
const plan = singleInstructionPlan(myInstruction);
 
const messageWithInstructions = appendTransactionMessageInstructionPlan(message, plan);

Appending a sequential instruction plan.

const plan = sequentialInstructionPlan([instructionA, instructionB, instructionC]);
const messageWithInstructions = appendTransactionMessageInstructionPlan(message, plan);

See

On this page