estimateAndSetResourceLimitsFactory

function estimateAndSetResourceLimitsFactory(
    estimateResourceLimits,
): <TTransactionMessage>(
    transactionMessage,
    config?,
) => Promise<TTransactionMessage>;

Returns a function that estimates the resource limits for a transaction message and sets them on the message.

For all versions, the compute unit limit is updated to the estimated value if it is not already set to an explicit, non-provisory value. The compute unit limit also treats the maximum (1,400,000) as non-explicit, so messages that pre-set the max for simulation get re-estimated.

For version 1 messages, the loaded accounts data size limit is updated only if it is unset or set to the provisory value of 0. An explicit value — including the runtime maximum — is left untouched, since callers who set it explicitly are signaling a deliberate choice.

This is designed to work with fillTransactionMessageProvisoryResourceLimits: first add provisory limits during transaction construction, then later estimate and replace them before sending.

Parameters

ParameterTypeDescription
estimateResourceLimitsEstimateResourceLimitsFunctionThe estimator function, typically created by estimateResourceLimitsFactory. You can also pass a custom wrapper that applies a buffer to the returned values.

Returns

A function that accepts a transaction message and returns it with resource limits set to the estimated values.

<TTransactionMessage>(transactionMessage, config?) => Promise<TTransactionMessage>

Example

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

On this page