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 Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[]; version: TransactionVersion; }> |
Parameters
| Parameter | Type | Description |
|---|---|---|
units | number | (previousUnits) => number | The new compute unit limit, or a function that takes the previous compute unit limit and returns the new limit. |
transactionMessage | TTransactionMessage | The transaction message to update. |
Returns
TTransactionMessage