Skip to content

Commit

Permalink
feat: added createTransaction (#6)
Browse files Browse the repository at this point in the history
* feat: added createTransaction

* chore: changeset
  • Loading branch information
nickfrosty authored Dec 9, 2024
1 parent 5becb9e commit 1438ba7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-wasps-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gill": patch
---

added the `createTransaction` function
1 change: 1 addition & 0 deletions packages/gill/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./const";
export * from "./rpc";
export * from "./explorer";
export * from "./transactions";
31 changes: 31 additions & 0 deletions packages/gill/src/core/transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
pipe,
isTransactionSigner,
createTransactionMessage,
setTransactionMessageFeePayer,
setTransactionMessageFeePayerSigner,
appendTransactionMessageInstructions,
setTransactionMessageLifetimeUsingBlockhash,
} from "@solana/web3.js";
import type { CreateTransactionInput } from "../types/transactions";

/**
* Simple interface for creating a Solana transaction
*/
export function createTransaction({
version,
feePayer,
instructions,
latestBlockhash,
}: CreateTransactionInput) {
return pipe(
createTransactionMessage({ version }),
(tx) => {
if ("address" in feePayer && isTransactionSigner(feePayer)) {
return setTransactionMessageFeePayerSigner(feePayer, tx);
} else return setTransactionMessageFeePayer(feePayer, tx);
},
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
(tx) => appendTransactionMessageInstructions(instructions, tx),
);
}
28 changes: 28 additions & 0 deletions packages/gill/src/types/transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type {
Address,
Blockhash,
IInstruction,
TransactionSigner,
TransactionVersion,
} from "@solana/web3.js";

export type CreateTransactionInput = {
/**
* Transaction version
* - `legacy` is commonly used
* - `0` is needed for use with Address Lookup Tables
* */
version: TransactionVersion;
/** List of instructions for this transaction */
instructions: IInstruction[];
/** Address or Signer that will pay transaction fees */
feePayer: Address | TransactionSigner;
/**
* Latest blockhash (aka transaction lifetime) for this transaction to
* accepted for execution on the Solana network
* */
latestBlockhash: Readonly<{
blockhash: Blockhash;
lastValidBlockHeight: bigint;
}>;
};

0 comments on commit 1438ba7

Please sign in to comment.