gill

updateOrAppendSetComputeUnitPriceInstruction

function updateOrAppendSetComputeUnitPriceInstruction<TTransactionMessage>(microLamports, transactionMessage): TTransactionMessage;

Updates the first SetComputeUnitPrice instruction in a transaction message with the given micro-Lamports, 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 = updateOrAppendSetComputeUnitPriceInstruction(
  // E.g. double the current price or set it to 10_000 if it isn't set.
  (currentPrice) => currentPrice === null ? 10_000 : currentPrice * 2,
  transactionMessage,
);

Type Parameters

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

Parameters

ParameterTypeDescription
microLamportsMicroLamports | (previousMicroLamports) => MicroLamportsThe new compute unit price, or a function that takes the previous price and returns the new one.
transactionMessageTTransactionMessageThe transaction message to update.

Returns

TTransactionMessage

On this page