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