diff --git a/web3.js/src/connection.js b/web3.js/src/connection.js index f8798a24c0..56d3367d58 100644 --- a/web3.js/src/connection.js +++ b/web3.js/src/connection.js @@ -3034,7 +3034,8 @@ export class Connection { const config: any = {encoding: 'base64'}; const args = [encodedTransaction, config]; const skipPreflight = options && options.skipPreflight; - const preflightCommitment = options && options.preflightCommitment; + const preflightCommitment = + (options && options.preflightCommitment) || this.commitment; if (skipPreflight) { config.skipPreflight = skipPreflight; diff --git a/web3.js/test/connection.test.js b/web3.js/test/connection.test.js index 9f4a9b961f..b237f00ed1 100644 --- a/web3.js/test/connection.test.js +++ b/web3.js/test/connection.test.js @@ -1361,6 +1361,25 @@ describe('Connection', () => { ).to.be.rejected; }); }); + + it('consistent preflightCommitment', async () => { + const connection = new Connection(url, 'singleGossip'); + const sender = new Account(); + const recipient = new Account(); + let signature = await connection.requestAirdrop( + sender.publicKey, + 2 * LAMPORTS_PER_SOL, + ); + await connection.confirmTransaction(signature, 'singleGossip'); + const transaction = new Transaction().add( + SystemProgram.transfer({ + fromPubkey: sender.publicKey, + toPubkey: recipient.publicKey, + lamports: LAMPORTS_PER_SOL, + }), + ); + await sendAndConfirmTransaction(connection, transaction, [sender]); + }); } it('get largest accounts', async () => {