Last active
April 19, 2021 09:39
-
-
Save scottphc/aaebf58d959b6313b2bf6175150d9f3c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 | |
} |
This file contains hidden or 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
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