getTransactionMessageComputeUnitLimit

function getTransactionMessageComputeUnitLimit(
    transactionMessage,
): number | undefined;

Returns the compute unit limit currently set on a transaction message, or undefined if none is set.

This function works with all transaction versions:

  • V1: Reads from the transaction message's config.computeUnitLimit.
  • Legacy / V0: Searches the instructions for a SetComputeUnitLimit instruction and decodes its value.

Parameters

ParameterTypeDescription
transactionMessageTransactionMessageThe transaction message to inspect.

Returns

number | undefined

The compute unit limit, or undefined if none is set.

Example

const limit = getTransactionMessageComputeUnitLimit(transactionMessage);
if (limit !== undefined) {
    console.log(`Compute unit limit: ${limit}`);
}

On this page