addSelfPlanAndSendFunctions

function addSelfPlanAndSendFunctions<TItem>(
    client,
    input,
): SelfPlanAndSendFunctions & TItem;

Adds self-planning and self-sending methods to an instruction or instruction plan.

This function augments the provided instruction or instruction plan with methods that allow it to plan and send itself using the provided client. It enables a fluent API where you can call methods like .sendTransaction() directly on the instruction.

The function supports both synchronous inputs (instructions, instruction plans) and promise-like inputs, making it suitable for use with async instruction builders.

Type Parameters

Type ParameterDescription
TItem extends | Instruction<string, readonly (AccountMeta<string> | AccountLookupMeta<string, string>)[]> | InstructionPlan | PromiseLike<Instruction<string, readonly (AccountMeta<string> | AccountLookupMeta<string, string>)[]>> | PromiseLike<InstructionPlan>The type of the instruction, instruction plan, or a promise resolving to one.

Parameters

ParameterTypeDescription
clientClientWithTransactionPlanning & ClientWithTransactionSendingA client that provides transaction planning and sending capabilities.
inputTItemThe instruction, instruction plan, or promise to augment with self-plan/send methods.

Returns

SelfPlanAndSendFunctions & TItem

The input augmented with SelfPlanAndSendFunctions methods.

Examples

Adding self-plan and send to a transfer instruction.

import { addSelfPlanAndSendFunctions } from '@solana/program-client-core';
 
const transferInstruction = addSelfPlanAndSendFunctions(
    client,
    getTransferInstruction({ payer, source, destination, amount })
);
 
// Now you can send directly from the instruction.
const result = await transferInstruction.sendTransaction();

Using with an async instruction builder.

const asyncInstruction = addSelfPlanAndSendFunctions(
    client,
    fetchAndBuildInstruction(/* ... */)
);
 
// The promise is augmented with self-plan/send methods.
const result = await asyncInstruction.sendTransaction();

See

SelfPlanAndSendFunctions

On this page