createTransactionPlanExecutor

function createTransactionPlanExecutor<TContext>(
    config,
): TransactionPlanExecutor<TContext>;

Creates a new transaction plan executor based on the provided configuration.

The executor will traverse the provided TransactionPlan sequentially or in parallel, executing each transaction message using the executeTransactionMessage function.

The executeTransactionMessage callback receives a mutable context object as its first argument, which can be used to incrementally store useful data as execution progresses (e.g. the latest version of the transaction message after setting its lifetime, the compiled and signed transaction, or any custom properties). This context is included in the resulting SingleTransactionPlanResult regardless of the outcome. This means that if an error is thrown at any point in the callback, any attributes already saved to the context will still be available in the plan result, which can be useful for debugging failures or building recovery plans. The callback must return either a Signature or a full Transaction object.

  • If that function is successful, the executor will return a successful TransactionPlanResult for that message. The returned signature or transaction is stored in the context automatically.
  • If that function throws an error, the executor will stop processing and cancel all remaining transaction messages in the plan. The context accumulated up to the point of failure is preserved in the resulting FailedSingleTransactionPlanResult.
  • If the abortSignal is triggered, the executor will immediately stop processing the plan and return a TransactionPlanResult with the status set to canceled.

Type Parameters

Type ParameterDefault type
TContext extends TransactionPlanResultContextTransactionPlanResultContext

Parameters

ParameterTypeDescription
configTransactionPlanExecutorConfig<TContext>Configuration object containing the transaction message executor function.

Returns

TransactionPlanExecutor<TContext>

A TransactionPlanExecutor function that can execute transaction plans.

Throws

SOLANA_ERROR__INSTRUCTION_PLANS__FAILED_TO_EXECUTE_TRANSACTION_PLAN if any transaction in the plan fails to execute. The error context contains a transactionPlanResult property with the partial results up to the point of failure.

Throws

SOLANA_ERROR__INSTRUCTION_PLANS__NON_DIVISIBLE_TRANSACTION_PLANS_NOT_SUPPORTED if the transaction plan contains non-divisible sequential plans, which are not supported by this executor.

Example

const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });
 
const transactionPlanExecutor = createTransactionPlanExecutor({
  executeTransactionMessage: async (context, message) => {
    const transaction = await signTransactionMessageWithSigners(message);
    context.transaction = transaction;
    await sendAndConfirmTransaction(transaction, { commitment: 'confirmed' });
    return transaction;
  }
});

See

TransactionPlanExecutorConfig

On this page