setTransactionMessageComputeUnitLimit

function setTransactionMessageComputeUnitLimit<TTransactionMessage>(
    computeUnitLimit,
    transactionMessage,
): TTransactionMessage;

Sets the compute unit limit for a transaction message.

This function works with all transaction versions:

  • V1: Sets the computeUnitLimit field in the transaction message's config.
  • Legacy / V0: Appends (or replaces) a SetComputeUnitLimit instruction from the Compute Budget program.

Type Parameters

Type ParameterDescription
TTransactionMessage extends TransactionMessageThe transaction message type.

Parameters

ParameterTypeDescription
computeUnitLimitnumber | undefinedThe maximum compute units (CUs) allowed, or undefined to remove the limit.
transactionMessageTTransactionMessageThe transaction message to configure.

Returns

TTransactionMessage

A new transaction message with the compute unit limit set.

Example

const txMessage = setTransactionMessageComputeUnitLimit(
    400_000,
    transactionMessage,
);

On this page