Skip to content

Builders Convenience Function#314

Open
inspi-writer001 wants to merge 6 commits intogillsdk:masterfrom
inspi-writer001:builders
Open

Builders Convenience Function#314
inspi-writer001 wants to merge 6 commits intogillsdk:masterfrom
inspi-writer001:builders

Conversation

@inspi-writer001
Copy link

Problem

#299
Sending multiple Basic Instructions with

createTransaction({
  instructions: [
    getTransferSolInstruction({
      amount: lamports(10_000n),
      destination: kp1.address,
      source: kp,
    }),
    getTransferTokensInstructions({
      amount: 10_000_000,
      authority: kp,
      destination: kp1,
      destinationAta: address("AERSsEKHCko4YPh6FSxtmVZLb4Hjd2dgdnUczkkXakDC"),
      feePayer: kp,
      mint: address("6mWfrWzYf5ot4S8Bti5SCDRnZWA5ABPH1SNkSq4mNN1C"),
      sourceAta: address("AERSsEKHCko4YPh6FSxtmVZLb4Hjd2dgdnUczkkXakDC"),
      tokenProgram: TOKEN_PROGRAM_ADDRESS,
    })[0],
    getAddMemoInstruction({ memo: "Hello memo", signers: [kp] }), // compute unit ix, priority fee ix
  ],
  feePayer: kp,
});

could be better, user has to pass the Keypair (kp) all around these instructions and code can quickly get messy just to transfer sol, a token, and add a memo in the same tx,

Summary of Changes

this could be the case

createInstructionBuilder().withMemo().withPriorityFee().withComputeLimit().transferSol().transferTokens().build()

with a single builder to chain these instructions together

Fixes

let new_ix = createInstructionBuilder(kp)
    .withMemo("Hello, this is an ix")
    .transferSol(lamports(lamportsToSend), destinationAddres)
    .transferTokens({
      amount: 5_000_000,
      destinationAta,
      sourceAta,
      mint: tokenMint,
      destination: destinationAddres,
      tokenProgram: TOKEN_PROGRAM_ADDRESS,
    }).withPriorityFee(10_000) // Optional, improves confirmation speed
    .withComputeLimit(500_000) // optional
    .build();
  const txSignature = await sendAndConfirmTransaction(new_ix);

Lesser code, more instructions, and you get to pass your keypair just once if it's the same for the entire transaction

@changeset-bot
Copy link

changeset-bot bot commented Oct 7, 2025

⚠️ No Changeset found

Latest commit: 55418ee

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@inspi-writer001 inspi-writer001 marked this pull request as ready for review October 7, 2025 18:26

export * from "./types";
export * from "./core";
export * from "./builders";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think just put this in core

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think just put this in core

Alright, I’ll do just that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants