UNPKG

@solana/transaction-messages

Version:

Helpers for creating transaction messages

105 lines 4.68 kB
import { TransactionMessageWithDurableNonceLifetime } from './durable-nonce'; import { BaseTransactionMessage } from './transaction-message'; /** * Given an instruction, this method will return a new transaction message with that instruction * having been added to the end of the list of existing instructions. * * @see {@link appendTransactionInstructions} if you need to append multiple instructions to a * transaction message. * * @example * ```ts * import { address } from '@solana/addresses'; * import { appendTransactionMessageInstruction } from '@solana/transaction-messages'; * * const memoTransaction = appendTransactionMessageInstruction( * { * data: new TextEncoder().encode('Hello world!'), * programAddress: address('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'), * }, * tx, * ); * ``` */ export declare function appendTransactionMessageInstruction<TTransactionMessage extends BaseTransactionMessage>(instruction: TTransactionMessage['instructions'][number], transactionMessage: TTransactionMessage): TTransactionMessage; /** * 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. * * @see {@link appendTransactionInstruction} if you only need to append one instruction to a * transaction message. * * @example * ```ts * 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, * ); * ``` */ export declare function appendTransactionMessageInstructions<TTransactionMessage extends BaseTransactionMessage>(instructions: ReadonlyArray<TTransactionMessage['instructions'][number]>, transactionMessage: TTransactionMessage): TTransactionMessage; type ExcludeDurableNonce<T> = T extends TransactionMessageWithDurableNonceLifetime ? BaseTransactionMessage & Omit<T, keyof TransactionMessageWithDurableNonceLifetime> : T; /** * Given an instruction, this method will return a new transaction message with that instruction * having been added to the beginning of the list of existing instructions. * * @see {@link prependTransactionInstructions} if you need to prepend multiple instructions to a * transaction message. * * @example * ```ts * import { address } from '@solana/addresses'; * import { prependTransactionMessageInstruction } from '@solana/transaction-messages'; * * const memoTransaction = prependTransactionMessageInstruction( * { * data: new TextEncoder().encode('Hello world!'), * programAddress: address('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'), * }, * tx, * ); * ``` */ export declare function prependTransactionMessageInstruction<TTransactionMessage extends BaseTransactionMessage>(instruction: TTransactionMessage['instructions'][number], transactionMessage: TTransactionMessage): ExcludeDurableNonce<TTransactionMessage>; /** * Given an array of instructions, this method will return a new transaction message with those * instructions having been added to the beginning of the list of existing instructions. * * @see {@link prependTransactionInstruction} if you only need to prepend one instruction to a * transaction message. * * @example * ```ts * import { address } from '@solana/addresses'; * import { prependTransactionMessageInstructions } from '@solana/transaction-messages'; * * const memoTransaction = prependTransactionMessageInstructions( * [ * { * data: new TextEncoder().encode('Hello world!'), * programAddress: address('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'), * }, * { * data: new TextEncoder().encode('How are you?'), * programAddress: address('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'), * }, * ], * tx, * ); * ``` */ export declare function prependTransactionMessageInstructions<TTransactionMessage extends BaseTransactionMessage>(instructions: ReadonlyArray<TTransactionMessage['instructions'][number]>, transactionMessage: TTransactionMessage): ExcludeDurableNonce<TTransactionMessage>; export {}; //# sourceMappingURL=instructions.d.ts.map