estimateAndSetComputeUnitLimitFactory

function estimateAndSetComputeUnitLimitFactory(
    estimateComputeUnitLimit,
): <TTransactionMessage>(
    transactionMessage,
    config?,
) => Promise<TTransactionMessage>;

Returns a function that estimates the compute unit limit for a transaction message and sets it on the message. If the message already has an explicit compute unit limit set (one that is not the provisory value of 0, and not the maximum of 1,400,000), the message is returned unchanged.

This is designed to work with fillTransactionMessageProvisoryComputeUnitLimit: first add a provisory limit during transaction construction, then later estimate and replace it before sending.

Parameters

ParameterTypeDescription
estimateComputeUnitLimitEstimateComputeUnitLimitFunctionThe estimator function, typically created by estimateComputeUnitLimitFactory. You can also pass a custom wrapper that adds a buffer (e.g. multiply the estimate by 1.1).

Returns

A function that accepts a transaction message and returns it with the compute unit limit set to the estimated value.

<TTransactionMessage>(transactionMessage, config?): Promise<TTransactionMessage>;

Type Parameters

Type Parameter
TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer<string>

Parameters

ParameterType
transactionMessageTTransactionMessage
config?Readonly<{ abortSignal?: AbortSignal; commitment?: Commitment; minContextSlot?: bigint; }>

Returns

Promise<TTransactionMessage>

Example

import { estimateAndSetComputeUnitLimitFactory, estimateComputeUnitLimitFactory } from '@solana/kit';
 
const estimator = estimateComputeUnitLimitFactory({ rpc });
const estimateAndSet = estimateAndSetComputeUnitLimitFactory(estimator);
const updatedMessage = await estimateAndSet(transactionMessage);

On this page