Skip to content

Instantly share code, notes, and snippets.

@scottphc
Last active April 19, 2021 09:39
Show Gist options
  • Save scottphc/aaebf58d959b6313b2bf6175150d9f3c to your computer and use it in GitHub Desktop.
Save scottphc/aaebf58d959b6313b2bf6175150d9f3c to your computer and use it in GitHub Desktop.
export async function sendTransaction(
connection: Connection,
wallet: any,
transaction: Transaction,
signers: Array<Account> = []
) {
transaction.recentBlockhash = (await connection.getRecentBlockhash(commitment)).blockhash
transaction.setSigners(wallet.publicKey, ...signers.map((s) => s.publicKey))
if (signers.length > 0) {
transaction.partialSign(...signers)
}
const signedTransaction = await wallet.signTransaction(transaction)
const rawTransaction = signedTransaction.serialize()
const txid: TransactionSignature = await connection.sendRawTransaction(rawTransaction, {
skipPreflight: true,
preflightCommitment: commitment
})
return txid
}
export async function sendTransactionWithProgramWallet(
connection: Connection,
wallet: any,
transaction: Transaction,
signers: Array<Account> = []
) {
transaction.recentBlockhash = (await connection.getRecentBlockhash(commitment)).blockhash
transaction.setSigners(wallet.publicKey, ...signers.map((s) => s.publicKey))
programWalletTransaction = await wallet.convertToProgramWalletTransation(transaction)
if (signers.length > 0) {
programWalletTransaction.partialSign(...signers)
}
const txid = await wallet.signAndSendTransaction(programWalletTransaction, {
skipPreflight: true,
preflightCommitment: commitment
})
return txid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment