@@ -14,13 +14,15 @@ import type { SolanaClient } from "gill";
1414import type { TransactionStatusEvent } from "../../types.js" ;
1515import {
1616 getSignatureFromBytes ,
17+ parseTransactionError ,
1718 pollConfirmTransaction ,
1819} from "@macalinao/gill-extra" ;
1920import {
2021 compressTransactionMessageUsingAddressLookupTables ,
22+ getSolanaErrorFromTransactionError ,
2123 signAndSendTransactionMessageWithSigners ,
2224} from "@solana/kit" ;
23- import { createTransaction } from "gill" ;
25+ import { createTransaction , simulateTransactionFactory } from "gill" ;
2426
2527export interface CreateSendTXParams {
2628 signer : TransactionSendingSigner | null ;
@@ -41,6 +43,7 @@ export const createSendTX = ({
4143 onTransactionStatusEvent,
4244 getExplorerLink,
4345} : CreateSendTXParams ) : SendTXFunction => {
46+ const simulateTransaction = simulateTransactionFactory ( { rpc } ) ;
4447 return async (
4548 name : string ,
4649 ixs : readonly Instruction [ ] ,
@@ -84,6 +87,24 @@ export const createSendTX = ({
8487 )
8588 : transactionMessage ;
8689
90+ // preflight
91+ if ( ! options . skipPreflight ) {
92+ const simulationResult = await simulateTransaction (
93+ finalTransactionMessage ,
94+ ) ;
95+ if ( simulationResult . value . err ) {
96+ onTransactionStatusEvent ( {
97+ ...baseEvent ,
98+ type : "error-simulation-failed" ,
99+ errorMessage : parseTransactionError (
100+ simulationResult . value . err ,
101+ simulationResult . value . logs ,
102+ ) ,
103+ } ) ;
104+ throw getSolanaErrorFromTransactionError ( simulationResult . value . err ) ;
105+ }
106+ }
107+
87108 onTransactionStatusEvent ( {
88109 ...baseEvent ,
89110 type : "awaiting-wallet-signature" ,
0 commit comments