diff --git a/web3.js/module.d.ts b/web3.js/module.d.ts index e492fd5dd1..c2e903c687 100644 --- a/web3.js/module.d.ts +++ b/web3.js/module.d.ts @@ -48,11 +48,13 @@ declare module '@solana/web3.js' { export type SendOptions = { skipPreflight?: boolean; + preflightCommitment?: Commitment; }; export type ConfirmOptions = { commitment?: Commitment; skipPreflight?: boolean; + preflightCommitment?: Commitment; }; export type ConfirmedSignaturesForAddress2Options = { diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js index 8db0a25223..d253737190 100644 --- a/web3.js/module.flow.js +++ b/web3.js/module.flow.js @@ -62,11 +62,13 @@ declare module '@solana/web3.js' { declare export type SendOptions = { skipPreflight: ?boolean, + preflightCommitment: ?Commitment, }; declare export type ConfirmOptions = { commitment: ?Commitment, skipPreflight: ?boolean, + preflightCommitment: ?Commitment, }; declare export type ConfirmedSignaturesForAddress2Options = { diff --git a/web3.js/src/connection.js b/web3.js/src/connection.js index d946ba9e07..ba7d878b80 100644 --- a/web3.js/src/connection.js +++ b/web3.js/src/connection.js @@ -48,9 +48,11 @@ type Context = { * * @typedef {Object} SendOptions * @property {boolean | undefined} skipPreflight disable transaction verification step + * @property {Commitment | undefined} preflightCommitment preflight commitment level */ export type SendOptions = { skipPreflight?: boolean, + preflightCommitment?: Commitment, }; /** @@ -59,10 +61,12 @@ export type SendOptions = { * @typedef {Object} ConfirmOptions * @property {boolean | undefined} skipPreflight disable transaction verification step * @property {Commitment | undefined} commitment desired commitment level + * @property {Commitment | undefined} preflightCommitment preflight commitment level */ export type ConfirmOptions = { skipPreflight?: boolean, commitment?: Commitment, + preflightCommitment?: Commitment, }; /** @@ -2755,7 +2759,20 @@ export class Connection { ): Promise { const args = [encodedTransaction]; const skipPreflight = options && options.skipPreflight; - if (skipPreflight) args.push({skipPreflight}); + const preflightCommitment = options && options.preflightCommitment; + + if (skipPreflight && preflightCommitment) { + throw new Error( + 'cannot set preflightCommitment when skipPreflight is enabled', + ); + } + + if (skipPreflight) { + args.push({skipPreflight}); + } else if (preflightCommitment) { + args.push({preflightCommitment}); + } + const unsafeRes = await this._rpcRequest('sendTransaction', args); const res = SendTransactionRpcResult(unsafeRes); if (res.error) {