gill

updateOrAppendSetComputeUnitLimitInstruction

function updateOrAppendSetComputeUnitLimitInstruction<TTransactionMessage>(units, transactionMessage): TTransactionMessage;

Updates the first SetComputeUnitLimit instruction in a transaction message with the given units, or appends a new instruction if none exists. A function of the current value can be provided instead of a static value.

Example

const updatedTransactionMessage = updateOrAppendSetComputeUnitLimitInstruction(
  // E.g. Keep the current limit if it is set, otherwise set it to the maximum.
  (currentUnits) => currentUnits === null ? MAX_COMPUTE_UNIT_LIMIT : currentUnits,
  transactionMessage,
);

Type Parameters

Type Parameter
TTransactionMessage extends Readonly<{ instructions: readonly IInstruction<string, readonly (IAccountLookupMeta<string, string> | IAccountMeta<string>)[]>[]; version: TransactionVersion; }>

Parameters

ParameterTypeDescription
unitsnumber | (previousUnits) => numberThe new compute unit limit, or a function that takes the previous compute unit limit and returns the new limit.
transactionMessageTTransactionMessageThe transaction message to update.

Returns

TTransactionMessage

On this page