chore: migrate to typescript
This commit is contained in:
committed by
Justin Starry
parent
3eb9f7b3eb
commit
f912c63b22
49
web3.js/src/util/send-and-confirm-transaction.ts
Normal file
49
web3.js/src/util/send-and-confirm-transaction.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import {Connection} from '../connection';
|
||||
import {Transaction} from '../transaction';
|
||||
import type {Account} from '../account';
|
||||
import type {ConfirmOptions} from '../connection';
|
||||
import type {TransactionSignature} from '../transaction';
|
||||
|
||||
/**
|
||||
* Sign, send and confirm a transaction.
|
||||
*
|
||||
* If `commitment` option is not specified, defaults to 'max' commitment.
|
||||
*
|
||||
* @param {Connection} connection
|
||||
* @param {Transaction} transaction
|
||||
* @param {Array<Account>} signers
|
||||
* @param {ConfirmOptions} [options]
|
||||
* @returns {Promise<TransactionSignature>}
|
||||
*/
|
||||
export async function sendAndConfirmTransaction(
|
||||
connection: Connection,
|
||||
transaction: Transaction,
|
||||
signers: Array<Account>,
|
||||
options?: ConfirmOptions,
|
||||
): Promise<TransactionSignature> {
|
||||
const sendOptions = options && {
|
||||
skipPreflight: options.skipPreflight,
|
||||
preflightCommitment: options.preflightCommitment || options.commitment,
|
||||
};
|
||||
|
||||
const signature = await connection.sendTransaction(
|
||||
transaction,
|
||||
signers,
|
||||
sendOptions,
|
||||
);
|
||||
|
||||
const status = (
|
||||
await connection.confirmTransaction(
|
||||
signature,
|
||||
options && options.commitment,
|
||||
)
|
||||
).value;
|
||||
|
||||
if (status.err) {
|
||||
throw new Error(
|
||||
`Transaction ${signature} failed (${JSON.stringify(status)})`,
|
||||
);
|
||||
}
|
||||
|
||||
return signature;
|
||||
}
|
Reference in New Issue
Block a user