diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js index b7a4356006..97832f15c7 100644 --- a/web3.js/module.flow.js +++ b/web3.js/module.flow.js @@ -232,5 +232,5 @@ declare module '@solana/web3.js' { from: Account, transaction: Transaction, runtimeErrorOk?: boolean, - ): Promise; + ): Promise; } diff --git a/web3.js/src/util/send-and-confirm-transaction.js b/web3.js/src/util/send-and-confirm-transaction.js index 8ac80538ba..5237c13ac4 100644 --- a/web3.js/src/util/send-and-confirm-transaction.js +++ b/web3.js/src/util/send-and-confirm-transaction.js @@ -4,6 +4,7 @@ import {Connection} from '../connection'; import {Transaction} from '../transaction'; import {sleep} from './sleep'; import type {Account} from '../account'; +import type {TransactionSignature} from '../transaction'; /** * Sign, send and confirm a transaction @@ -13,12 +14,13 @@ export async function sendAndConfirmTransaction( from: Account, transaction: Transaction, runtimeErrorOk: boolean = false -): Promise { +): Promise { let sendRetries = 10; + let signature; for (;;) { const start = Date.now(); - const signature = await connection.sendTransaction(from, transaction); + signature = await connection.sendTransaction(from, transaction); // Wait up to a couple seconds for a confirmation let status = 'SignatureNotFound'; @@ -38,7 +40,7 @@ export async function sendAndConfirmTransaction( if ( (status === 'Confirmed') || (status === 'ProgramRuntimeError' && runtimeErrorOk) ) { - return; + break; } if (status !== 'AccountInUse' || --sendRetries <= 0) { @@ -48,5 +50,7 @@ export async function sendAndConfirmTransaction( // Retry in 0..100ms to try to avoid another collision await sleep(Math.random() * 100); } + + return signature; }