appendTransactionInstruction if you only need to append one instruction to a transaction message.
import { address } from '@solana/addresses';
import { appendTransactionMessageInstructions } from '@solana/transaction-messages';
const memoTransaction = appendTransactionMessageInstructions(
[
{
data: new TextEncoder().encode('Hello world!'),
programAddress: address('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'),
},
{
data: new TextEncoder().encode('How are you?'),
programAddress: address('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'),
},
],
tx,
);
Given an array of instructions, this method will return a new transaction message with those instructions having been added to the end of the list of existing instructions.