-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: added createTransaction * chore: changeset
- Loading branch information
1 parent
5becb9e
commit 1438ba7
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"gill": patch | ||
--- | ||
|
||
added the `createTransaction` function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}>; | ||
}; |