import type { Wallet } from "@saberhq/solana-contrib"; import type { ConfirmOptions, Connection, Signer, Transaction, } from "@solana/web3.js"; export async function executeTransaction( connection: Connection, wallet: Wallet, tx: Transaction, config?: { signers?: Signer[]; silent?: boolean; confirmOptions?: ConfirmOptions; errorHandler?: (e: unknown) => string; } ): Promise { const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash( config?.confirmOptions?.commitment || "processed" ); tx.recentBlockhash = blockhash; tx.feePayer = wallet.publicKey; tx = await wallet.signTransaction(tx); if (config?.signers?.length) { tx.partialSign(...config.signers); } try { const signature = await connection.sendRawTransaction( tx.serialize(), config?.confirmOptions ); await connection.confirmTransaction( { blockhash, signature, lastValidBlockHeight, }, config?.confirmOptions?.commitment || "processed" ); return signature; } catch (e) { throw e; // if (config?.errorHandler) { // // console.error(e); // throw new Error(config?.errorHandler(e)); // } else { // if (!config?.silent) { // logError(e); // } // throw e; // } } }