Skip to content

Commit bb8685b

Browse files
committed
Add confirmations to TransactionResponse (ethers-io#4094).
1 parent 3c1bad2 commit bb8685b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src.ts/providers/provider.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,26 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
13451345
return this.provider.getTransaction(this.hash);
13461346
}
13471347

1348+
/**
1349+
* Resolve to the number of confirmations this transaction has.
1350+
*/
1351+
async confirmations(): Promise<number> {
1352+
if (this.blockNumber == null) {
1353+
const { tx, blockNumber } = await resolveProperties({
1354+
tx: this.getTransaction(),
1355+
blockNumber: this.provider.getBlockNumber()
1356+
});
1357+
1358+
// Not mined yet...
1359+
if (tx == null || tx.blockNumber == null) { return 0; }
1360+
1361+
return blockNumber - tx.blockNumber + 1;
1362+
}
1363+
1364+
const blockNumber = await this.provider.getBlockNumber();
1365+
return blockNumber - this.blockNumber + 1;
1366+
}
1367+
13481368
/**
13491369
* Resolves once this transaction has been mined and has
13501370
* %%confirms%% blocks including it (default: ``1``) with an

0 commit comments

Comments
 (0)